Lab 2: Checkers and Strategies

In this lab, you will refactor your code from Lab 1 so it uses the Strategy Pattern. This will demonstrate how the pattern can improve cohesion.

Approach

  1. Fix any issues noted by your instructor in your previous lab’s submission.

  2. Create an interface or abstract class for MoveBehavior. It must have isValidOrdinaryMove and getCapturedPiece methods in it.

  3. Create classes derived from MoveBehavior. These will reflect the different ways to move pieces (such as red vs. black and king vs. regular piece). You will implement the behaviors below; write skeleton classes for now.

  4. Introduce a MoveBehavior member in Piece. This member must be updated each time there is a change in the boolean used to capture whether the piece represents a king.

  5. Design and implement the behavior classes you introduced. This includes determining whether to use abstract or interface, determining how they will access the piece they control, determining each method’s arguments and return values, and deciding if anything needs to be moved or made public. Sketching a UML diagram or sequence diagram may improve your design.

  6. Eliminate control coupling and logical cohesion from the isValidOrdinaryMove and getCapturedPiece methods. That is, these methods should have no if statements based on whether the piece represents a king. There will be places in your final solution where there are if statements checking a piece’s color; it is only the if statements checking for king pieces in these methods that must be removed.

Submission

Please see your instructor’s guidance on submitting this lab.