(obviously need getters setters etc) |
It's a trend to use getters/setters, however this isn't quite right. The trend started right at the beginning with Microsoft VBXs'. Objects are
not records, and they shouldn't be thought of as such. It limits, in your imagination, how they might be combined.
In code:
1 2 3 4 5 6 7 8
|
class Entity {
int guid;
Component* components[INDEXMAX];
public:
void addComponent(ComponentIndex i, Component* c);
void print();
};
|
It doesn't make sense for addComponent to take an index. How can you possibly know where it ought to go? If you need an index, maybe is should return the insertion point.
For example, what does this mean?
1 2 3
|
// same ComponentIndex
e->addComponent(2, new Timer(READ_TIMEOUT, 75));
e->addComponent(2, new TransactionCompleteNotify());
|
There's also a technical matter. What values do these values take?
1 2 3 4
|
enum ComponentIndex {
HEALTH,
INDEXMAX
};
|
And in that contect, what does this mean?
1 2 3
|
class Entity {
int guid;
Component* components[INDEXMAX];
|
Start again. Define your interfaces (for Entity and Component), then decide how those classes might implement those interfaces. When you begin with the implementation, you constrain your thinking from the start.