Page 1 of 1

Am I going about this the OO way?

Posted: Tue Aug 09, 2011 3:01 pm
by BlobOfFailure
I've been working on an engine I started working on awhile ago, but abandoned due to lack of interest, and I'm currently re-writing the majority of it due to poor design, and I was wondering if I was going about a component based system the right way. Basically currently I have several manager classes, each of the also have a representative component class that contains a static instance of the manager as well any functions that would be commonly used among any class inheriting from that class, but it just feels too much like a singleton to me, and I want to make sure that it's following the object oriented design theory before I re-write everything to work around that system.

An example of what I'm talking about if I didn't clearly explain it,

Code: Select all

// The component calss
class GraphicalComp
{
public:
static GraphicsManager m(); 

void setImage(Image img);
void setPos(int x, int y);
//ect
};

//and then the manager

class GraphicsManager
{
public:

void addSprite(GraphicalComp g);

void render();

private:
std::vector<GraphicalComp> sprites;
};

and then when I create a class that requires something to be rendered on the screen,

Code: Select all

class Player: public Sprite
{
Player();
//Contents of player class
};


Re: Am I going about this the OO way?

Posted: Wed Aug 10, 2011 5:01 am
by ismetteren
BlobOfFailure wrote:I've been working on an engine I started working on awhile ago, but abandoned due to lack of interest, and I'm currently re-writing the majority of it due to poor design, and I was wondering if I was going about a component based system the right way. Basically currently I have several manager classes, each of the also have a representative component class that contains a static instance of the manager as well any functions that would be commonly used among any class inheriting from that class, but it just feels too much like a singleton to me, and I want to make sure that it's following the object oriented design theory before I re-write everything to work around that system.

An example of what I'm talking about if I didn't clearly explain it,

Code: Select all

// The component calss
class GraphicalComp
{
public:
static GraphicsManager m(); 

void setImage(Image img);
void setPos(int x, int y);
//ect
};

//and then the manager

class GraphicsManager
{
public:

void addSprite(GraphicalComp g);

void render();

private:
std::vector<GraphicalComp> sprites;
};

and then when I create a class that requires something to be rendered on the screen,

Code: Select all

class Player: public Sprite
{
Player();
//Contents of player class
};

I'm not quite sure i understand what you are trying to do. What are the components using the static instance of the manager for. Also, if the manager is going to manage components wouldn't using pointers/references for the components be better, since you want the changes some manager(say the physics manager) makes to a component to reflect in the other managers(say the Render manager).

Re: Am I going about this the OO way?

Posted: Wed Aug 10, 2011 7:59 am
by BlobOfFailure
Sorry about how confusing my question was, the static instances of the manager were basically being used as a singleton and my question was, and I was asking was that proper. Yes it should be a pointer or reference, but I was just trying to explain how I was going about my horrid system of managers and components, but I realized that I was basically using singletons and messy code, and learned the proper alternative. Basically I had no idea how to go about a component based system and thought that each class should be able to add it's self to the manager...