java - Avoiding instanceof with overloaded mutators -


i have 2 classes inherit player: simpleplayer , interleavedplayer.

class b has these methods: setplayer(simpleplayer player) , setplayer(interleavedplayer player)

class has player field, designed either simpleplayer or interleavedplayer. class wants call b.setplayer() on these players, without concerning subclass of player object is.

i overloaded b.setplayer() subclasses in order avoid using instanceof in generalized b.setplayer(player player) method.

but on a's call b.setplayer(), symbol not found error referring b.setplayer(player).

what design approach should use here resolve issue? (a creates players, in theory "knows" it's passing b. however, because of way indiscriminately treats it's player seems make sense having player stuff to, rather having distinguish between simpleplayer , interleavedplayer).

have overloaded methods in a:

private player;  public void setplayer(simpleplager player) {     this.player = player;     b.setplayer(player); }  // similar interleavedplayer 

or if call comes within constructor, can overload too.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -