Factory

The factory is a maker of a component. After the config parser parses the definition XML file, the component object’s constructor is stored in a factory as a map structure. When the specified component is needed, the factory is responsible for creating the component instance. The Workparea and service component are both generated in this way.

Actually, the factory is an index set of component constructors, in which there are a lot of mappings between component name and component constructor. If you want to obtain a specific component, the factory will find out its constructor according to its name, and then generate a component instance only by the new method. Factory only returns a naked component without initialization and attributes injection which is done by engine.

The infrastructure of factory is shown as follows:

the infrastructure of factory

If you want to make factory work well, before getting the instance of a component, you must register the constructor into the factory. You can perform the registering by calling register method of the factory. After registering the component, you can obtain the component by calling the getComponent method of the factory. Following is a code sample:
var factory = new BTTFactory();
factory.register ("Page", BTTPage);
function BTTPage(){
	this.name = "Page";	
	//...
}
var pageObj = factory.getComponent("Page");//the pageObj is a instance of BTTPage