Hi. I'm programming for a simple game.
I designed component classes for my objects. There is a HealthComponent class. This class has a HP and state as a member variable. A HP is for the object like a human, monster. And a state is a object's state, dead or alive.
but I need a component for the object who needs a state but doesn't needs a HP.
So, I thought about that. I have two ways.
- Just implement two classes. HealthComponent and NonLifeComponent?(btw plz recommend a class's name..)
A NonLifeComponent class has only a state, expired or not.
- Make a inheritance relation between HealthComponent and NonLifeComponent.
A NonLifeComponent will be a base class. the member is same with (1). And HealthComponent will be a derived class. In this case, the name of NonLifeComponent is a nonsense.
Maybe (2) will be like next code.
// Plz recommend a class name.
class XXComponent
{
...
eState m_eState; // expired or not
};
class HealthComponent : public XXComponent
{
...
int m_iHP;
}
And (1) will be like this.
class NonLifeComponent
{
eState m_eState; // expired or not
};
class HealthComponent
{
int m_iHP;
eState m_eState; // Alive or Dead
};
Which one is more good way?