Views |
|
ObjectFactory
[edit] ObjectFactory : Class registration and XML loading mechanism[edit] GoalsThe factory mechanism (see the link Factory method pattern) is used in SOFA to create and initialize objects, given their classname and a set of parameters. Also, as many SOFA classes are templated, an additionnal template specification might be provided, or deduced from other objects (i.e. a ForceField is created with the same datatypes as the associated MechanicalState). As a secondary objective, the factory can be used to query informations on the available classes, to produce documentation pages, or present it in the GUI (possibly allowing in the future the user to graphically create the scene). [edit] Current implementationThe current Factory (as of january 2007) has no notion of template specification, and does not support listing informations on the registered classes. Also, the creation mechanism is using a global templated method "template<T> void create(T*& obj, ObjectDescription* arg)" that all classes must implement nearly from scratch. Since the introduction of Fields to describe most parameters, this mechanism introduce many redundancies. Classes are registered by creating a Creator<T> object, specifying the name of the class. However, this registration does not store other attributes (short description, classes this object implements, license, list of parameters (fields), ...). [edit] Proposed new designs[edit] Design 1Instead of relying on instantiation templated create<> methods and Creator<> objects, it would be simpler to add the necessary information inside the class itself, maybe as static variables or methods. This way most classes won't have to redefine a new create method, and thoses that requires it can do so inside the class itself, and potentially reusing the create method from base classes. Also, currently the name of the class is specified in every Creator<> instance associated to it, as well as in the getTypeName() virtual method (which by default get the name of the class using RTTI). Instead we can rely on a static typeName<T>() method for both the Factory registration and the getTypeName method. This method shoud return something very similar to the c++ class name, as it will allow users to easily connect the XML files with the code. If another (maybe shorted) name is wanted, then it can be added as an alias. |
|
| This page was last modified 00:48, 30 January 2007. |