multiple-inheritance - 如何在多继承中合并属性
问题描述
重复从具有相同父级的2个类继承,我陷入了继承2次相同属性的经典案例。我想将 2 个属性合并为一个,并尝试使用 undefine 来完成,但它给我一个编译错误。我看到的另一个解决方案是重命名父母双方之一的属性,但据我所知,我的 D 类的每个实例都有一个无用的属性,这不是我想要的......
Error: Undefine subclause lists name of frozen feature or attribute or
C external.
What to do: unless you can change the status of the feature in the parent,
remove its name from Undefine subclause since it cannot be undefined.
如何从重复继承的类中合并 2 个属性
class A
serial: STRING
end -- class A
class B
inherit
A
end -- class B
class C
inherit
A
end -- class C
class D
inherit
B
undefine
serial -- error seems to appear here in that case
end
C
end -- class D
解决方案
没有理由取消定义将与来自不同继承路径的相同版本合并的功能。在示例中,属性serial
未在B
、C
和中更改D
。因此,继承B
和C
不进行任何改编都是可以的:
class D inherit
B
C
end
推荐阅读
- sonarqube - 分析成功后如何在单独的调用中将 JaCoCo 报告上传到 SonarQube?
- makefile - CalculiX 安装错误 etime (在函数 `second_':)
- css - 是否可以在 CSS 中设置子字符串的样式?
- python - 如何在 Flask admin 中的 GUI/请求中更改输入数据,然后再转换为表单?如果编辑/创建模型
- php - 第 60 行 /bootstrap/start.php 中的 Laravel 错误 \Illuminate\Foundation\start.php 没有这样的文件
- javascript - AWS Lambda 和 DynamoDB 上的 Node.js
- youtube - 有没有办法邀请用户使用 API 管理 Youtube?
- python - Django rest框架,序列化方法字段不保存对db的更改?
- jquery - iCheck 库的 ifChanged 事件仅针对第一个单选按钮的更改触发
- django - Django - 来自不同模型的upload_to动态路径