Am I going about this the OO way?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
BlobOfFailure
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 17
Joined: Sat Nov 27, 2010 10:38 am
Programming Language of Choice: C++

Am I going about this the OO way?

Post 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
};

User avatar
ismetteren
Chaos Rift Junior
Chaos Rift Junior
Posts: 276
Joined: Mon Jul 21, 2008 4:13 pm

Re: Am I going about this the OO way?

Post 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).
Image ImageImage Image
User avatar
BlobOfFailure
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 17
Joined: Sat Nov 27, 2010 10:38 am
Programming Language of Choice: C++

Re: Am I going about this the OO way?

Post 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...
Post Reply