class Component { public: void Init( void ) = 0; void Update( float dt ) = 0; void ShutDown( void ) = 0; void SendMSG( MSG *msg ) = 0; protected: CID id; // Component id GameObject *m_owner; bool m_active; // delayed destruction } class GameObject { public: void SendMSG( MSG *msg ); // forward msgs to all components; Component *GetComponent( CID id ); // Can do binary search with std::map on CID void Update( float dt ); // Run update on all components void AddComponent( Component *comp ); private: std::map m_componentMap; }; // Adding components, all default constructed with initial values GameObject *obj = Factory->CreateObject( ); obj->AddComponent( Factory->CreateComponent( "Tansform" ); obj->AddComponent( Factory->CreateComponent( "Sprite" ); obj->AddComponent( Factory->CreateComponent( "RigidBody" ); Component *sprite = obj->GetComponent( Spriteid ); sprite->Update( ); // render an object