This mixin applies the Singleton design pattern to a class, by providing access to a single instance and preventing the creation of any others.
To use this mixin, you must define the identifier SINGLETON_CLASS as the class under compilation and then include the module. For example:
class myclass
.define SINGLETON_CLASS, myclass
.include "MIXINS:Singleton"
method initialize, void
proc
;Do any initialization of the one instance.
end
You must supply the instance method "initialize" shown above, which may be public, private, or protected. This method will be invoked when the one and only instance of the class is created, which happens on the first access to the "instance" property.
To access the single instance of the class, use the static property "instance". For example:
myclass.instance.somemethod()
This mixin creates a private default constructor for the class, so don't try to define your own.