[Newbies] Smalltalk constants
mark at ociweb.com
Wed Nov 5 12:09:12 UTC 2008
On Nov 5, 2008, at 3:43 AM, Delyan Kalchev wrote:
> Is there a good way to create a named constant in Smalltalk. For
> example the name MyNamedConstant to be constant bind to the number 2
> or even to a non-constant object, like the pseudo-variables nil or
> true are bind to their objects and the programmer cannot change them
> to point to other objects.
The recommended way to implement constants in Smalltalk is by writing
a class method that simply returns the constant value. For example,
see the class method pi in the Math class. Actually this class also
represents constants as class variables whose values are set in the
class initialize method. In this case the class variable Pi is set in
initialize and that is returned from the class method pi.
More information about the Beginners