Advertisement

OOP Design Question.

Started by May 17, 2001 07:51 AM
2 comments, last by JSCFaith 23 years, 8 months ago
Hey This is a rather simple question. I have a base-class(GameObject) and a few classes that inherit from it. Should each sub-class have its own linked list or should the base-class? Or should the base-class and sub-class have their own linked lists? The reason I ask is because I have a few functions that require I search through all the GameObjects. If I only had linked lists in the sub-classes, it would be pretty hard to implement. Now, if the linked list was in the base class only. I would have to search through a much bigger list for the things that only require a sertain sub-class object, and that might impact the speed. Well, what should I do? Thanks, James
This is probably way off base but, what about having the list of game objects as it''s own entity? Then just implement a search function in the base classes. That way you have only one list and can call the searches from the appropriate instances of the sub-classes. If this makes no sense (which it probably doesn''t) post a little more specific info.

good luck;
Prairie
Advertisement
Hi,
Why not use a template class for the linked list, you could also sort the cGameObjects based on some variable.
Example:
template
class CLinkedList
{
struct SNode
{
T *pObj;
sNode *pNext, *pPrev;
};
sNode *pTop, *pBottom, *pMiddle, *pCurrent;
....
};

class CGameObject : public IUnknown
{....
};

Now say, you need to keep track of CMissles (inherited from CGameObject) in CAircraft (also inherited from CGameObject), you could do the following:

class CAircraft : public CGameObject
{
public:
CLinkedList missleList;
/*
Add functions...
*/
};

Hope this helps.

-Ankur M.
Umm... why not do both?
A list with all game objects can probably be usefull sometimes...
but way to inefficent when you only need missiles or cars or something... but hey... maybe you should ask yourself if they really in the same entity altogheter...

This topic is closed to new replies.

Advertisement