拥有可以重新定义的常数的最佳方法是什么?
具有仅返回“绿色”或“蓝色”的函数时,是否需要再次创建字符串,性能问题还是没关系?
据我了解,曾经无法再次宣布...
答案 0 :(得分:2)
可以将特征重新定义为任何其他特征。例子是
class A feature
color: STRING once Result := "green" end
end
class B inherit A redefine color end feature
color: STRING once Result := "blue" end
end
此外,清单字符串本身也可以定义一次:
class A feature
color: STRING do Result := once "green" end
end
class B inherit A redefine color end feature
color: STRING do Result := once "blue" end
end
两种情况下的行为相同,因此您甚至可以混合使用两种变体。性能可能有所不同,但仅略有不同。在这两种情况下,都不会在每次调用时都创建新的字符串。