I remembered that I was able to do something like
red, green, blue, foo, bar: INTEGER is unique
in Eiffel, is it obsolete? for what reason? What does replace it?
I remembered that I was able to do something like
red, green, blue, foo, bar: INTEGER is unique
in Eiffel, is it obsolete? for what reason? What does replace it?
Unique constant attributes are now obsolete. A new type-safe mechanism is under development. Meanwhile, the closest alternative is to use constant attributes:
red: INTEGER = 1
green: INTEGER = 2
blue: INTEGER = 3
foo: INTEGER = 4
bar: INTEGER = 5
Of course, it's also possible to design a type-safe variant yourself:
expanded class QUX inherit
ANY
redefine
default_create
end
feature {NONE} -- Creation
default_create do make (1) end
feature {QUX} -- Initialization
make (value: like item) do item := value end
feature -- Enumeration
red: QUX
once
Result.make (1)
ensure
instance_free: class
end
green: QUX
once
Result.make (2)
ensure
instance_free: class
end
feature -- Access
item: INTEGER
end
Then in the code you would write:
x: QUX
...
x := {QUX}.red
if x = {QUX}.green then ...
Note. You may need to install EiffelStudio 18.07 or later to use class features.