When to decide if your class should be a component?
When it is any or more of the following:
- configurable
- data you want stored and easily accessible from anywhere in the code
- action
Example
A new component always has to inherit from a parent class which is also a component. A simple example is the class common::Group, which adds actually no extra functionality.
namespace common {
{
public:
static std::string
type_name () {
return "Group"; }
Group (
const std::string&
name ) : Component(name) {}
virtual ~Group() {}
};
}
}
Noteworthy here is:
- Group inherits from Component
- The constructor of a Component takes only 1 std::string, i.e. the name the component gets
- The component must have a static function Group::type_name() defined, returning the class name
- Following the class name is first the API macro related to this namespace (here Common_API). This macro is usually defined in the library of this namespace. (LibNamespace.hpp)