Currently methods in chess.ChessPiece
(previously chess.pieces.ChessPiece
) are public
for Chess
to be able to use chess-specific functionality in pieces.
However ChessPiece
is then exposed for users as an interface with information relevant for chess players.
Alongside all useful methods, those public
methods are also exposed. This violates ISP since they are irrelevant in many places, and encapsulation since they provide information that should be hidden.
I've tried isolating appropriate interface, however this doesn't work, because Game
expects objects with those specific methods in the public interface, e.g. in the getLegalMoves(int, ChessPiece)
method.
I can see two solutions here:
- Create
abstract ChessPiece
which exposes publicly only relevant methods, and has a package-private field with AbstractChessPiece
that can be used by the game
- Make all methods in
ChessPiece
protected
and disallow using this interface inside pieces
package, i.e. pieces can operate only on concrete piece types.