As mentioned on this question, there is no way to define a constant which I can redefine into a descendant.
In many of my cases, I'd like to have a constant which I can redefine. The alternatives I see to avoid a creation on each consultation which doesn't make sense would be
That's not doable
class A
feature -- Access
Default_value: STRING = "some A value"
end -- Class
class B
inherit
B
redefine
Default_value
end
feature -- Access
Default_value: STRING = "some B value"
end -- Class
Alternative with once instance_free
class A
feature -- Access
Default_value: STRING
once
Result := "some A value"
ensure
instance_free: class
end
end -- Class
class B
inherit
B
redefine
Default_value
end
feature -- Access
Default_value: STRING
once
Result := "some B value"
ensure
instance_free: class
end
end -- Class
As far as I understand, the once wouldn't be created with B value as the A class value would be taken
Alternative with attribute
class A
feature -- Access
Default_value: STRING
attribute
Result := "some A value"
ensure
instance_free: class
end
end -- Class
class B
inherit
B
redefine
Default_value
end
feature -- Access
Default_value: STRING
attribute
Result := "some B value"
ensure
instance_free: class
end
end -- Class
Would it be the only and good practice to do it?