I'm trying to grok the Strategy pattern and came up with the following example:
- I'd like to create new games based on chess except with pieces that move differently.
- I also want to use the Strategy pattern to inject behaviors (how they can move) into the pieces.
But if we have Board
, Piece
, and MoveBehavior
objects
Board
->Piece
because aBoard
containsPiece
sPiece
->Board
because a piece needs to pass in theBoard
as a param toMoveBehavior
which needs theBoard
to decide what moves are acceptable.
How can we get rid of this circular dependency? Also, isn't this a common problem in more realistic examples because behaviors need large enough state to make decisions? I think if the behavior is super simple it's not that big a deal to not use the Strategy pattern.