Runtime components : Core components : ElementFactory : Tasks : Scope
  
Scope
When you define a definition for an element, you specify how to create the element and define the dependency to other elements. In fact, the definition is a template from which to create an element, you can create multiple instances of element from the definition.
The attribute Scope specifies how many instances of element you can create from the definition. The ElementFactory supports two scopes:
Supported scopes
singleton
There is only one instance for the element definition in one ElementFactory.
prototype
The element instance is created every time on the invocation of getElement(String id).
Note It is not required to define attribute Scope in every element definition. There is a default Scope value singleton. To change the default scope of the element, see Customizing ElementFactory for more detail.
See
Singleton
Prototype
See also
Tasks
Singleton
When the scope is defined to singleton, there is only one instance for the definition. In other words, there is only one instance for each element id. The singleton instance is cached in ElementFactory. On the sequence invocation of getElement(String id), the cached instance will be returned instead of creating a new instance.
The following diagram shows how the singleton scope works:
diagram shows how the singleton scope works
Following is a sample definition for singleton scope:
<mypackage.SimpleElement id="aSimpleElement" Scope="singleton"/>
See also
Scope
Prototype
When the scope is defined to prototype, ElementFactory creates a new instance on every invocation of getElement(String id).
The following diagram shows how prototype scope works:
diagramshows how prototype scope works
Following is a sample definition for the prototype scope:
<mypackage.SimpleElement id="aSimpleElement" Scope="prototype"/>
See also
Scope