CoreFactory

Kind of class:public class
Package:com.bourre.core
Inherits from:none
Author:Francis Bourre
Classpath:com.bourre.core.CoreFactory
File last modified:Monday, 24 November 2008, 11:36:49
A factory for object creation. The CoreFactorycan build any object of any type. The CoreFactoryis intensively used in the IoC assembler of LowRA.

Summary


Class methods
  • buildInstance (qualifiedClassName:String, args:Array = null, factoryMethod:String = null, singletonAccess:String = null) : Object
    • Builds an instance of the passed-in class with the specified arguments

Class methods

buildInstance

public static function buildInstance (
qualifiedClassName:String, args:Array = null, factoryMethod:String = null, singletonAccess:String = null) : Object

Builds an instance of the passed-in class with the specified arguments
passed to the class constructor. The function can also work with singleton
factory and factory methods.

When trying to create an object, the function will work as below :

  1. The function try to retreive a reference to te specified class, if
    the class cannot be found in the current application domain the function
    will fail with an exception.
  2. Then the function will look to a factory method, if one have been
    specified, if the singletonAccess is also specified, the
    function retreive a reference to the singleton instance and then call
    the factory method on it. If there is no singleton access, the function
    call the factory method directly on the class.
  3. If singletonAccess is specified and factoryMethodparameter is null, this method will try to return an instance using singleton
    access parameter as static method name of the class passed.
  4. If there is neither a factory method nor a singleton accessor, the
    function will instantiate the class using its constructor.

In AS3, the constructor property of a class is not a function
but an object, resulting that it is not possible to use the applyor call method on the constructor of a class. The workaround
we use is to create wrapping methods which correspond each to a specific call
to a class constructor with a specific number of arguments, in that way, we can
select the right method to use according to the number of arguments specified
in the buildInstance call. However, there's a limitation, we decided
to limit the number of arguments to 30 values.

Parameters:
qualifiedClassName:
the full classname of the class to create as returned
by the getQualifiedClassName function
args :
array of arguments to transmit into the constructor
factoryMethod :
the name of a factory method provided by the class
to use in place of the constructor
singletonAccess :
the name of the singleton accessor method if the
factory method is a member of the singleton instance
Returns:
  • an instance of the specified class, or null
Throws:
  • {VISDOC_LINK_0}ReferenceError — The specified classname cannot be found
    in the current application domain
Example:
  • Creating a Point instance using the CoreFactory class :
    CoreFactory.buildInstance( "flash.geom::Point", [ 50, 50 ] );

    Using the factory method createObject of the class to create the instance :
    CoreFactory.buildInstance( "com.package::SomeClass", ["someParam"], "createObject" );