   A good way of creating components
  I've really attached to the component based design and use it for a lot of the things I do ( scene graph right now ). I have one question about creating new components. Somewhere down the road, I'm sure I will add more components. What would be the best way to set up my component creation so that I'd have to do as little work as possible. The way I have done it in the past is that the biggest parent system will register component creators with the factory before anyone uses it. I'm curious if there is a simpler way.   
  In my component system:Sim has a FactorySim has many SystemsSystems have many ComponentsComponents have creation functionsSystems contain the registration code for the components they can create. The sim can populate a factory by iterating through it's systems.void Simulation::Run(){  for each m_Systems as system    system->RegisterComponents( m_Factory );}...virtual void MySystem::RegisterComponents( Factory& f ){  f.AddComponent( "MyComponent", MyComponent::Create );}Although I actually use macros to write my boilerplate code (like the RegisterComponents function)...class MySystem : public System{  mpDeclareSystem( MySystem )};...mpImplementSystem( MySystem )mpRegisterComponent( MyComponent )mpEndImplementSystem...but I'm sure many would prefer the verbose code than magic macros.   ;  So it looks like you have one line you add to register a new component. I guess it can't get any better than that.   ;  I've used other systems in the past which have slightly less code - they use a global object whose constructor puts data into a global factory:class Registrar{public:  Registrar( const char* name, Component*(*pfn)() )  {    FactorySingleton::Register( name, pfn );  }};#define RegisterComponent( name ) \    Registrar g_##name__( #name, name::Create );  //#define DeclareComponent( name )\    static Component* Create() { return new name; }  //...//MyComponent.hclass MyComponent : public Component{  DeclareComponent( name )};...//MyComponent.cppImplementComponent( MyComponent )I used to like these approaches, but these days I don't like the fact that it relies on a singleton, and on some obscure platforms you've got to force the linker not to throw out the Registrar objects (as they're never used, besides the side-effects from construction).   