jeudi 4 mai 2017

Allow reverse operation in undo only

I'm trying to implement simple Solitaire game.

Let's assume we have a class called SourceCardDeck which represents source deck of cards. This class has an ability to pop one card, but it doesn't have an ability to push card back (which is okay, user should not be able to store card on the source deck).

Now, I need to implement undo operation. How can I do that without any method to push card back? I've heard about Command pattern, but it works only with reverse method available. Also what about Card and its ability to turn up? Should card have method to turn down? User usually cannot turn card down again. But in undo it's needed.

How to make this proper and clean way?

Aucun commentaire:

Enregistrer un commentaire