Note: I am aware of the poor wording of the title but I was unable to come up with a better one. If anyone has a better idea, then please edit the title.
I'm trying to recreate a card game but kind of struggling with a problem. Every card in the game has a
color (enum) and
rank (enum). Some of the cards have some special abilities which require additional data. These cards always have a special color only given to cards with special abilities. The
Game has a stack to which played cards are added through a method
An example special ability is changing the color of the card on the top of the stack. The new color is totally up to the player to decide. The problem is that this new color needs to be decided when the card is played and before that the special card's color is just
SPECIAL. But how do I pass the new color data in a nice way (i.e. so I don't need to use
instanceof and extract the data but just get it as
card.getColor())? Ideally I'd like it to be a special card before and after playing it to disguise as a normal card (or make it seem like to). If possible I'd still want to be able to retrieve the original, special card.
I thought about solving this by creating a
FakeCard and adding a method to
SpecialCard to generate the
FakeCard and pass the required data to that method but I'm afraid of additional coupling that would occur as different special cards require different additional data and don't want to violate Open/Closed principle (using this approach would require me to). I can't think of anything else though. Do you have any suggestions as to how approach this problem?