Reputation: 5083
How to set a constant refering to another class constant in Eiffel?
Something like that doesn't compile unfortunately
Default_log_level: like {MY_LOGGER}.log_level = {MY_LOGGER}.Log_level_info
Upvotes: 0
Views: 52
Reputation: 141
Constant attributes can only be made of a manifest constant, but a possible workaround could be to use frozen once functions:
frozen Default_log_level: INTEGER
once
Result := {MY_LOGGER}.Log_level_info
ensure
definition: Result = {MY_LOGGER}.Log_level_info
end
frozen
means that it cannot be redefined in descendant classes (like constant attributes).
Unfortunately, the type of once
functions cannot rely on anchored types, hence the use of INTEGER
instead of like {MY_LOGGER}.log_level
.
And finally, the drawback with this solution is that it cannot be used where constant attributes are expected (e.g. in inspect
instructions).
Upvotes: 2
Reputation: 5790
Constant attributes cannot be defined using other constant attributes in the current version of Eiffel.
Upvotes: 2