I have a problem with management classes and interfaces in Java. I have a interface Superhero and other interface called Human. Then I have various classe of Human type for example PeterParker. At the end I have a Interface called HumanAndSuper that has this method:
public interface HumanAndSuper{
public Superhero fromHumanToSuperhero();
public Human fromSuperheroToHuman();
}
public interface SuperHero{
public void attacks();
}
When I create a Human object,for example PeterParker,in this class I have a private nested Superhero class. For example:
public class PeterParker implements Human,HumanAndSuper{
//Constructors
public Superhero fromHumanToSuperhero(){
//the human turns into superhero associated
return new Spiderman();
}
public Human fromSuperheroToHuman(){
//the superhero becomes a human
return this;
}
public void speaks(){//It's a example
//Implementation
}
private class Spiderman extends PeterParker implements SuperHero{
public void attacks(){
//Implementation
}
}
}
In practice the implementation of the superhero relative to human is internal to the same class of the human. what I would like is to be able to instantiate a human with the same variable can pass from human to superhero and vice versa. For example:
PeterParker peter=new PeterParker();//Human
peter.speaks();
peter=peter.fromHumanToSuperhero();//peter becomes spiderman
peter.attacks();//method in Spiderman class
peter=peter.fromSuperheroToHuman();//spiderman becomes Human
how can I achieve such a thing?