samedi 25 novembre 2017

Calling a method of a different object without breaking encapsulation

I have an object GameLogic which has a Player (interface) object.

GameLogic has a method getAvailableMoves() which is used inside GameLogic to let Player know about his available moves.

I'm currently implementing an AIPlayer (implements Player) which should use the Minimax algorithm as a strategy. For that to happen, I want to be able to use GameLogic's getAvailableMoves() method from inside AIPlayer. However, I'd like to do that without breaking encapsulation. That is to say that I'm trying to avoid passing GameLogic as a reference to Player.

What is the appropriate solution for this scenario? I assume I should use a Design Pattern but I'm not sure which.

Aucun commentaire:

Enregistrer un commentaire