Gets a Singleton instance of derived class
OutputVar := MfSingletonBase.Instance
Value
instance of Derived Class
Gets a Singleton instance of derived class
Throws MfNotSupportedException if attempt to set value.
Read-only Property.
Instance Property always returns the same instance of the derived class class.
MsgBox % SingletonHello.Instance.Message
SingletonHello.Instance.Value := "Way too cool!"
MsgBox % SingletonHello.Instance.Message
ExitApp
class SingletonHello extends MfSingletonBase
{
static _instance := Null ; Static var to contain the singleton instance
m_Value := Null
__New() {
base.__New()
this.m_Value := "Hello World"
}
; GetInstance() is required to be overridden from the SingletonBase base class
GetInstance() { ; Overrides base
if (MfNull.IsNull(SingletonHello._instance)) {
SingletonHello._instance := new SingletonHello()
}
return SingletonHello._instance
}
; DestroyInstance() is required to be overridden from the SingletonBase base class
DestroyInstance() {
SingletonHello._instance := Null ; Clears current instance and releases memory
}
; Properties Start
Value[]
{
get {
return this.m_Value
}
set {
this.m_Value := value
return this.m_Value
}
}
Message[]
{
get {
return MfString.Format("The Value is currently:'{0}'", this.Value)
}
set { ; Read-only Property
ex := new MfNotSupportedException(MfEnvironment.Instance.GetResourceString("NotSupportedException_readonly_Property"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
}
; Properties End
}