Packagecom.developmentarc.framework.utils
Classpublic class InstanceFactory
SubclassesSingletonFactory

The InstanceFactory acts as a ClassFactory but only generates a new instance of an item on the first request. This Factory is similar to a Singleton Pattern, but the instance is not stored in a static property, instead the instances are stored locally within the InstanceFactory.

This class is useful when only a single instance of an item is required but not on a Framework/Application level. If you need a Framework/Application level Singleton instance, use the SingletonFactory to generate your instance.



Protected Properties
 PropertyDefined by
  instanceTable : HashTable
Stores the local instances for the factory.
InstanceFactory
Public Methods
 MethodDefined by
  
Constructor.
InstanceFactory
  
Used to remove all current instances from the Factory.
InstanceFactory
  
clearInstance(type:Class):void
Used to remove a specific instance type from the factory.
InstanceFactory
  
getInstance(type:Class):*
Used to get access to an instance of the Class type requested.
InstanceFactory
Property detail
instanceTableproperty
protected var instanceTable:HashTable

Stores the local instances for the factory.

Constructor detail
InstanceFactory()constructor
public function InstanceFactory()

Constructor.

Method detail
clearAllInstances()method
public function clearAllInstances():void

Used to remove all current instances from the Factory.

clearInstance()method 
public function clearInstance(type:Class):void

Used to remove a specific instance type from the factory. This method checks to see if the requeted type has an intance in the table, and if so the instance is removed. This enables getInstance() to create a new instance the next time the method is called. If the instance type does not exist, nothing occurs.

Parameters
type:Class — The type of instance to look for and remove.
getInstance()method 
public function getInstance(type:Class):*

Used to get access to an instance of the Class type requested. This method first determines if the Class type has been requested before. If the Class has never been requested, the method creates a new instance of the Class, stores it in a table and then returns a reference to the Class.

If the Class type has been requested previously, the method returns the previously generated instance.

Parameters
type:Class — The Class of the instance to return.

Returns
* — The generated instance of the Class.