A quick question, about encapsulation

Started by
1 comment, last by return0 12 years, 3 months ago
I have a IChessPIece class that encapsulates an sf::Sprite. sf::Sprite has its own interface. Would it be a better idea to have IChessPiece create a interface where it delegates its job to sf::Sprite, or would it be better to just returned sf::Sprite by reference? For example,

class IChessPiece{
void animateTo(...);
void showPossibleMoveLoaction(GameBoard& board);

sf::Sprite getSprite()const{ return m_sprite; }
sf::Sprite getSprite()const{ return m_sprite; }
public:
sf::Sprite m_sprite;
enum { PAWN, KNIGHT, ... };
};


or


class IChessPiece{
void animateTo(...);
void showPossibleMoveLoaction(GameBoard& board);

void setLocation(..){ m_sprite.SetLocation(...); }
void setSize(...){ m_sprite.SetSize(...); }
//.. and so on
public:
sf::Sprite m_sprite;
enum { PAWN, KNIGHT, ... };

};

Or maybe a possible combination of the two to make it easier on the user? All works, I guess, but just seeing what you guys thought about it.
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github
Advertisement
The first. You should be composing, not encapsulating here - there is no reason why IChessPiece should have to wrap all the methods of the Sprite class.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

That type looks confused, is it a model or a viewmodel?

Can't figure out how to edit on phone screen, hit post by accident, meant to add it's mixing MVVM concerns.

When will a decent mobile version of this site be available, like the old one?
Can't figure out how to edit on phone screen, hit post by accident, meant to add it's mixing MVVM concerns.

When will a decent mobile version of this site be available, like the old one?

This topic is closed to new replies.

Advertisement