Packagecom.ericfeminella.utils
Classpublic final class SingletonManager

All static class which provides an API which enforces classes which are to follow the Singleton pattern are only ever have a single instance instantiated per application, by monitoring the instantiation of derived classes this requirement is ensured, thus elliminating the Singleton implementation code from the actual class implementation.

Upon instantiation of a Singleton class, the class constructor invokes SingletonManager.validateInstance and simply passes a reference to the instance.


Example
this can be seen in the following

          SingletonManager.validateInstance( this );
          

The fully qualified class name is then used as the unique key in the HashMap instance (singletons). The class name / key is then assigned a Boolean value of true. When a subsequent instantiation of the Singleton class occurs the Singleton class repeats the process of invoking SingletonManager.validateInstance to see if the Singleton class has been mapped previously, and if so an exception is thrown.

Classes must invoke SingletonManager.validateInstance from within their constructor in order to garuntee they are only to have single instance created, hence the term Singleton.

The following example demonstrates how a class can invoke SingletonManager.validateInstance in order to simplify the Singleton construction process by delegating Singleton Management to a specific object rather than the class implementation itself
     package com.examples
     {
         public class SomeSingleton
         {
             // Defines the singleton instance of SomeSingleton
             public static const instance:SomeSingleton = new SomeSingleton();

             // Singelton class passes in a reference of the instance,
             // SingletonManager determines the fully qualified name
             // of the class and validates the instance
             public function SomeSingleton()
             {
                 SingletonManager.validateInstance( this );
             }
         }
     }
     

The above example guarantees that only one instance of the example class "SomeSingleton" can ever be instantiated.



Public Methods
 MethodDefined by
  
validateInstance(instance:*):void
[static] Validates a new Singleton class instance to determine if the class has previously been instantiated, if so, an Exception is thrown, thus indicating that the class is a Singleton and is only intended to have a single instance instantiated
SingletonManager
Method detail
validateInstance()method
public static function validateInstance(instance:*):void

Validates a new Singleton class instance to determine if the class has previously been instantiated, if so, an Exception is thrown, thus indicating that the class is a Singleton and is only intended to have a single instance instantiated

Parameters
instance:* — class instance which has been instantiated