I have following classes structure extention:
Entity > Creature > (abstract)Player > Mage.
In Mage class I implement interface iCastable with method castSpell(). In main method I create new Mage(...).
Problem is that when I send it as a prop of Player class someMethod(Player player), I cannot use methods implemented from interface iCastable. I can only use methods from Creature class via player.getCreaure.whaterver() because Player extend it. How can I solve that issue?
I do not want to send it as a prop of Mage class, because I want to use all my other classes like Warrior for example. I also want to avoid player instanceof Mage, because if I had 1000 classes I must do 1000 check for every method. Do you have any ideas how to solve that?
EDIT added code
public class Creature extends Entity {...}
public abstract class Player extends Creature {
public Player(String name) {
super(name);
}
public abstract void attack();
}
public class Mage extends Player implements iCastable {
...
@Override
public void castSpecial() {...}
}
public static void main(String[] args) {
Mage mage = new Mage("Mage");
Duel duel = new Duel(mage, monsters);
}
public class Duel {
private Player player;
...
public Duel(Player player, ArrayList<Monster> monsters) {
this.player = player;
...
}
private void castSpecial() {
// error here
player.castSpecial();
}
}
I am trying to do something like player.getInstanceClass(mage, warrior or whatever).cashSpecial()
iCastablerather than implementing itsomeMethod(Player player)defined ?Playerthen the method's internal functionality shouldn't care what kind ofPlayer. If the method's internal functionality is specific to aMagethen it should expect aMage. What exactly doessomeMethod()do? If you were to give it a meaningful and descriptive name, what would it be?