I am trying to make a class in Eiffel, consisting of a few attributes and functions. I keep getting issues with the attributes not being either visible to setName or not being initialised correctly. The compiler error is: VEVI: Variable is not properly set. Attribute(s): name. I want to be able to instantiate a TESTER object in APPLICATION and invoke these methods.
class
TESTER
create
make
feature
name: STRING
score: INTEGER
make
do
io.putstring ("I am making TESTER%N")
end
sleep
do
io.put_string ("TESTER is sleeping%N")
end
setName (name_: STRING)
do
name := name_
end
end
This has to do with void-safety ( https://www.eiffel.org/doc/eiffel/Void-safe%20programming%20in%20Eiffel ).
There are several ways to address the issue in the example, two of them are shown below:
Declare
nameasdetachable. By default class types areattached. Changing the type todetachableallows the attributenameto be initialized to the default valueVoid, i.e. not attached to any object.Attach an object to the attribute
namein the creation proceduremake.The simplified version of the rule says that all attributes should be set at the end of a creation procedure.