Interfaces on c++

  abstract, c++, chess, inheritance, interface

I wanted to ask you which version is better to use.
I am talking about de inheritance of the pawn.
in the first example i have a double inheritance, in the second i have just one and i want to know which version is better to use.

Look at the class Pawn.
first:

class AbstractPiece
{
protected:
    std::string name;
    PieceColor pieceColor;
    Square currentSquare;
    char _buff[50];
public:
    AbstractPiece(PieceColor _pieceColor);
     std::string getName();
     PieceColor getPieceColor();
    Square getCurrentSquare();
     void setCurrentSquare(Square _currentSquare);

    friend std::ostream& operator<<(std::ostream &c, AbstractPiece &p);

};

class InterfaceMovable
{
public:
    virtual std::list<Location> getValidMoves(Board board)=0;
    virtual void makeMove(Square square)=0;

};

class Pawn : public AbstractPiece, public InterfaceMovable
{
public:
    Pawn(PieceColor _pieceColor);
    std::list<Location> getValidMoves(Board board);
    void makeMove(Square square);

};

or like this:

class AbstractPiece
{
protected:
    std::string name;
    PieceColor pieceColor;
    Square currentSquare;
    char _buff[50];
public:
    AbstractPiece(PieceColor _pieceColor);
     std::string getName();
     PieceColor getPieceColor();
    Square getCurrentSquare();
     void setCurrentSquare(Square _currentSquare);
     virtual std::list<Location> getValidMoves(Board board)=0;
    virtual void makeMove(Square square)=0;
    friend std::ostream& operator<<(std::ostream &c, AbstractPiece &p);

};


class Pawn : public AbstractPiece
{
public:
    Pawn(PieceColor _pieceColor);
    std::list<Location> getValidMoves(Board board);
    void makeMove(Square square);

};

Source: Windows Questions C++

LEAVE A COMMENT