如何合并 multi-inheritence 中的属性
how to merge an attribute in multi-inheritence
重复继承2个具有相同parent的class,我陷入了classic继承2次相同属性的情况。我想将 2 个属性合并为一个,并尝试使用 undefine 来实现,但它给我带来了编译错误。
我看到的另一个解决方案是重命名两个 parent 之一的属性,但据我所知,我的 D class 的每个实例都会有一个无用的属性,这不是我想要的...
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 个属性 classes
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
不做任何适配就OK了:
class D inherit
B
C
end
如果您要合并的是两个不相关的属性(不是来自同一个父属性),您应该重新定义它们:
class A
feature
serial: STRING
end
class B
feature
serial: STRING
end
class C
inherit
A
redefine
serial
end
B
redefine
serial
end
feature
serial: STRING
end
如您所见,编译器不会让您取消定义属性,即使目标是将它与另一个属性合并。
重复继承2个具有相同parent的class,我陷入了classic继承2次相同属性的情况。我想将 2 个属性合并为一个,并尝试使用 undefine 来实现,但它给我带来了编译错误。 我看到的另一个解决方案是重命名两个 parent 之一的属性,但据我所知,我的 D class 的每个实例都会有一个无用的属性,这不是我想要的...
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 个属性 classes
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
不做任何适配就OK了:
class D inherit
B
C
end
如果您要合并的是两个不相关的属性(不是来自同一个父属性),您应该重新定义它们:
class A
feature
serial: STRING
end
class B
feature
serial: STRING
end
class C
inherit
A
redefine
serial
end
B
redefine
serial
end
feature
serial: STRING
end
如您所见,编译器不会让您取消定义属性,即使目标是将它与另一个属性合并。