= HowTo: Adding a new class to the hierarchy = [[TOC]] The class hierarchy in Orxonox is controlled by [wiki:doc/Identifier Identifiers]. Every class has it's identifier. This page explains how a new class is added correctly to the class hierarchy. Features available to classes in the hierarchy: * [wiki:howto/Identifier Identifier] * [wiki:doc/Factory Factory] * [wiki:howto/Iterator ObjectLists] * [wiki:howto/ConfigValue Config-Values] * [wiki:howto/XMLPort XML-Loadable] * more... == Objects == If you want to create a new object (an object in the sense of a game-related class), you have to inherit directly or indirectly from [wiki:doc/BaseObject] and call '''RegisterObject('''''ClassName''''')''' (see [wiki:doc/CoreIncludes]) in the constructor of this class. If you want this class to be [wiki:doc/Loader loadable] from an [wiki:doc/XMLPort XML-file], add '''CreateFactory('''''ClassName''''')''' outside of the code. This creates a mapping between the string "ClassName" and the class itself (see [wiki:doc/Factory]). *.h file: {{{ #include "core/BaseObject.h" class MyClass : public BaseObject { public: MyClass(); }; or #include "objects/SomeOtherObject.h" class MyClass : public SomeOtherObject { public: MyClass(); }; }}} *.cc file: {{{ #include "core/CoreIncludes.h" CreateFactory(MyClass); // optional // Constructor: MyClass::MyClass() { RegisterObject(MyClass); } }}} == Interfaces == Interfaces in Orxonox aren't objects by themselfes, but provide functions and features for real objects. Those objects inherit from the interfaces, additionally to [wiki:doc/BaseObject] (or a derivative). Interfaces have to inherit virtually from [wiki:doc/OrxonoxClass] and call '''RegisterRootObject('''''InterfaceName''''')''' in the constructor. *.h file: {{{ #include "core/OrxonoxClass.h" class MyInterface : virtual public OrxonoxClass { public: MyInterface(); }; }}} *.cc file: {{{ #include "core/CoreIncludes.h" // Constructor: MyInterface::MyInterface() { RegisterRootObject(MyInterface); } }}}