ios - Is it possible (or advisable) for a method to recognize its caller? -
i'm developing simple game player needs roll die , "the computer" needs it.
i roll
method performs differently each type of player.
it's set bool
parameter called isplayer
(vs. iscomputer). players pass true value, computer false. there's if
statements in method act accordingly.
this seems clunky me. there better way?
i thinking of creating playertype
enum , each player have type still need pass type method. or change game variable type , method recognize that.
any thoughts helpful. thanks.
no seems fine , much-used , simple pattern.
a bool
fine time there 2 types of player (or behaviour) , moving enum
if number of players extends beyond 2.
alternatively there polymorphism roll
method behaves differently depending on subclass implements it. require no parameters passed behaviour locked in class.
Comments
Post a Comment