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.
Fix any issues noted by your instructor in your previous lab’s submission.
Create an interface or abstract class for MoveBehavior
. It must have isValidOrdinaryMove
and getCapturedPiece
methods in it.
Create RegularBehavior
and KingBehavior
classes derived from MoveBehavior
.
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.
Design and implement the behavior classes you introduced. This includes determining whether to use abstract or interface, how they will access the piece they control and determining each method’s arguments and return values, and deciding if anything needs to be moved or made public. Remember that good design mandates that data not be more public than necessary; for example, exposing all of the inner state of a Piece
would be poor design. Sketching a UML diagram or sequence diagram may improve your design.
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 that must be removed.
Please see your instructor’s guidance on submitting this lab.