Hello,
Suppose I have a chess game. I make a nice class to handle an entire player's pieces:
class c_ChessTeam
{
private:
// all pieces derive from class c_ChessPiece
c_Rook Rook[2];
c_King King;
c_Queen Queen;
c_Bishop Bishop[2];
c_Knight Knight[2];
c_Pawn Pawn[8];
public:
. . .
};
But what if I'm playing by the rule that, when a pawn has reached the edge of the board, they turn into a different piece (for example, a knight)? Then my pawn has to change classes into a c_Knight object. To avoid this, I could do this:
class c_ChessTeam
{
private:
c_ChessPiece Rook[2];
c_ChessPiece King;
c_ChessPiece Queen;
c_ChessPiece Bishop[2];
c_ChessPiece Knight[2];
c_ChessPiece Pawn[8];
public:
. . .
};
Now, all my pieces have no unique "rules" on how they act, and I've essentially created a checkers game. I could code the c_ChessPiece class to have all the information for each of the unique pieces, but that could lead to the program running not so smooth.
What would someone do in this situation, where they need their object to essentially change classes?