|
ASL
|
A Factory allows creating objects given a class name as a String.
They are used through pointers to their base class and through virtual functions. A Factory is created for a given base class, and subclasses must be registered with ASL_FACTORY_REGISTER() before use.
For example, assuming there is a generic possibly abstract base class Animal, we can create a subclass Dog and register it for instantiation by name.
Now an object of class Animal can be created anywhere only knowing the definition of the abstract class Animal.
A Factory can be exported from a dynamic library for use with runtime dynamic loading. In this case the library must export its catalog of subclasses with a macro:
Now a client application can load the library at runtime with the Library class import its Animal factory and create objects.
Classes | |
| class | Factory< T > |
| A Factory allows creating objects given a class name as a String. More... | |
Macros | |
| #define | ASL_FACTORY_REGISTER(Base, Class) |
Registers class Class in the factory for class Base for instantiation by name (Class must be a subclass of Base). | |
| #define | ASL_FACTORY_REGISTER_AS(Base, Class, Name) |
Registers class Class in the factory for class Base for instantiation by the alternative name Name. | |
| #define | ASL_FACTORY_EXPORT(Base) |
Exports all registered classes derived from Base for instantiation from a dynamic library. | |
| #define | ASL_FACTORY_IMPORT(Base, lib) |
Imports all registered classes derived from Base from the given dynamic library. | |
| #define ASL_FACTORY_IMPORT | ( | Base, | |
| lib | |||
| ) |
Imports all registered classes derived from Base from the given dynamic library.
That library is a Library object that must be open and persistent (e.g. created in the heap so it exists while its classes are used).