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 Workplace Area and service component are both generated in this way.
Actually, the factory is just 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 firstly, and then generate a component instance only by the new method. Factory only returns a naked component without initialization and attributes injection which are done by engine, see the next section.
The infrastructure of factory is shown as follows:
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