Originally Posted by
\007
I wasn't thinking of renaming Sprites as movable-- just in my head I thought an Object and Sprite are essentially the same thing. The only difference is a Sprite can be moved so needs to handle input. On the other hand a Tile is the same as an Object but the difference is a Tile doesn't need to be moved so doesn't need to have input handled.
Sorry that I wasn't very clear. I was not thinking that you should rename your Sprites to Movable. I was just thinking that you should create a Movable interface and have your Sprite class inherit that interface. Not knowing exactly what methods a "Movable" object would have, I made up my own:
Code:
class IMovable
{
public:
void MoveTo(struct Coordinates position) = 0;
struct Coordinates GetPosition() = 0;
};
That's probably over-simplifying. Maybe you would really have MoveLeft, MoveUp, MoveRight, and MoveDown methods. At any rate this is just an interface. You then need to implement it in your Sprite class:
Code:
class Sprite : public IMovable
{
private:
struct Coordinates position;
public:
Sprite(struct Coordinates startPosition);
~Sprite();
/* IMovable implementation */
void MoveTo(struct Coordinates position);
struct Coordinates GetPosition();
};
Sprite::Sprite(struct Coordinates startPosition)
{
this->position = startPosition;
}
Sprite::~Sprite()
{
}
void Sprite::MoveTo(struct Coordinates position)
{
this->position = position;
}
struct Coordinates Sprite::GetPosition()
{
return this->position;
}
Then when you collect a bunch of objects that are movable, you check for their inheritance of the IMovable interface:
Code:
...
std::vector<IMovable *> sprites;
...
and you'll always know that the MoveTo and GetPosition methods will be part of those objects. This is how you program against an interface.
Originally Posted by
\007
I guess I was over complicating my designs?
I don't think that you're over-complicating your designs. Just know that a simpler interface on the front usually requires more complex thinking and design patterns on the back.
Originally Posted by
\007
How do you help manage your designs while expanding your application? I pretty much hit the end of my initial design plans and now I am expanding things, in other words I am winging it now.
Most of the time when I am expanding my application, if I need new things, maybe that I didn't think of before, I have need of refactoring quite a bit. Sometimes things have gotten too messy in the past, and I must virtually start over. It is always best to sit and think about designs and plan them out as much as possible before you touch a line of code. Also if you haven't studied design patterns, then I would suggest you do. There are several good books, and Wikipedia has a series on them. Not all of them are applicable everywhere, obviously. And try not to misuse them - some people misuse certain patterns especially. But overall, design patterns result in cleaner, more understandable, and more correct, performant code.