MfSingletonBase

Namespace ›› System ››
Parent Previous Next

MfSingletonBase Class

(Inherits from MfObject)

Abstract class for singleton pattern Classes.
Classes such as MfFlagsAttribute are derived from MfSingletonBase

Links

Properties, Methods

Constructors


Name

Description

Constructor()

Constructor for Abstract Class MfSingletonBase.

Properties


Name

Description

Instance

Gets a Singleton instance of derived class

Methods


Name

Description

AddAttribute()

Adds MfAttribute extended items to extended classes. Inherited from MfObject.

CompareTo()

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. Inherited from MfObject.

DestroyInstance()

Sets current instance of singleton derived class to null. Abstract Method.

Equals(obj)

Compares obj to current instance to see if they are the same. Inherited from MfObject.

GetAttribute(index)

Gets an MfAttribute of the class. Inherited from MfObject.

GetAttributes()

Gets a MfGenericList of MfAttribute that Contains the attributes for the current class instance. Inherited from MfObject.

GetHashCode()

Gets A hash code for the current MfObject. Inherited from MfObject.

GetInstance()

Gets the instance of the Singleton. Protected Abstract method.

GetIndexOfAttribute(attrib)

Gets the zero-based index value of the position of MfAttribute within the instance of the class. Inherited from MfObject.

GetType()

Gets the Type for the for the Class .Inherited from MfObject.

HasAttribute(attrib)

Gets if the current instance of class derived from MfSystemException has MfAttribute. Inherited from MfObject.

Is(type)

Gets if current instance of object is of the same type. Inherited from MfObject. Inherited from MfObject.

IsInstance()

Get if the current class is an instance. Inherited from MfObject.

MemberwiseClone()

Creates a shallow copy of the current MfObject instance. Inherited from MfObject.

ToString()

Gets a string representation of the MfObject. Inherited from MfObject.

VerifyIsInstance([ClassName, LineFile, LineNumber, Source])

Verifies the the current object is set to an instance. Inherited from MfObject.

VerifyIsNotInstance([MethodName, LineFile, LineNumber, Source])

Verifies the the current object is NOT set to an instance. Used in Static methods. Inherited from MfObject.

Example

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
}