Skip to content

Not possible to use inheritance for ChessPiece #54

Description

@leesjensen

The tests directly create a ChessPiece in TestUtilities.java. This makes it impossible for a student to implement inheritance as a solution for implementing the different chess pieces.

    public static ChessBoard loadBoard(String boardText) {
        var board = new ChessBoard();
        for (var c : boardText.toCharArray()) {
            switch (c) {
               // ...
                default -> {
                    ChessGame.TeamColor color = Character.isLowerCase(c) ? ChessGame.TeamColor.BLACK : ChessGame.TeamColor.WHITE;
                    var type = CHAR_TO_TYPE_MAP.get(Character.toLowerCase(c));
                    var position = new ChessPosition(row, column);
                    var piece = new ChessPiece(color, type);
                    board.addPiece(position, piece);
                    column++;
                }
            }
        }
    ```

Instead we could create a factory method on ChessPiece that `loadBoard` would call. 

We went away from the factory pattern a couple years ago. I'm not sure why that was and so we might run into a problem if we partially move back to it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions