Skip to main content
added 25 characters in body
Source Link

Try a visitor with 2 methods with the same name, but one taking RegularCard as a parameter and one with SpecialCard.

Then you can define a method in BaseCard which will take visitor and invoke with itself resolving the subtype.

Something like this:

class CardDealer { void play(RegularCard card) { ... } void play(SpecialCard cardspecialCard) { ... } } abstract class Card { draw(CardDealer visitor) { visitor.play(this); } } 

or

interface Playable { void play(CardDealer dealer); } 

and overwrite method accordingly, in this case you can use different names for visitor methods

Try a visitor with 2 methods with the same name, but one taking RegularCard as a parameter and one with SpecialCard.

Then you can define a method in BaseCard which will take visitor and invoke with itself resolving the subtype.

Something like this:

class CardDealer { void play(RegularCard card) { ... } void play(SpecialCard card) { ... } } abstract class Card { draw(CardDealer visitor) { visitor.play(this); } } 

Try a visitor with 2 methods with the same name, but one taking RegularCard as a parameter and one with SpecialCard.

Then you can define a method in BaseCard which will take visitor and invoke with itself resolving the subtype.

Something like this:

class CardDealer { void play(RegularCard card) { ... } void play(SpecialCard specialCard) { ... } } abstract class Card { draw(CardDealer visitor) { visitor.play(this); } } 

or

interface Playable { void play(CardDealer dealer); } 

and overwrite method accordingly, in this case you can use different names for visitor methods

added 25 characters in body
Source Link

Try a visitor with 2 methods with the same name, but one taking RegularCard as a parameter and one with SpecialCard.

Then you can define a method in BaseCard which will take visitor and invoke with itself resolving the subtype.

Something like this:

class PlayActionCardDealer { void play(RegularCard card) { ... }   void play(SpecialCard card) { ... } } interfaceabstract class Card { visitdraw(PlayActionCardDealer visitor) { visitor.play(this); } } 

Try a visitor with 2 methods with the same name, but one taking RegularCard as a parameter and one with SpecialCard.

Then you can define a method in BaseCard which will take visitor and invoke with itself resolving the subtype.

Something like this:

class PlayAction { play(RegularCard card) { ... } play(SpecialCard card) { ... } } interface Card { visit(PlayAction visitor) { visitor.play(this); } 

Try a visitor with 2 methods with the same name, but one taking RegularCard as a parameter and one with SpecialCard.

Then you can define a method in BaseCard which will take visitor and invoke with itself resolving the subtype.

Something like this:

class CardDealer { void play(RegularCard card) { ... }   void play(SpecialCard card) { ... } } abstract class Card { draw(CardDealer visitor) { visitor.play(this); } } 
Source Link

Try a visitor with 2 methods with the same name, but one taking RegularCard as a parameter and one with SpecialCard.

Then you can define a method in BaseCard which will take visitor and invoke with itself resolving the subtype.

Something like this:

class PlayAction { play(RegularCard card) { ... } play(SpecialCard card) { ... } } interface Card { visit(PlayAction visitor) { visitor.play(this); }