Interface
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package state;
/**
*
* @author toucatronic
*/
public interface Pokemon {
public void evolui(Treinador t);
public String getNome();
public void ataque();
}
Classe Treinador
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package state;
/**
*
* @author toucatronic
*/
public class Treinador {
Pokemon p;
public void pokebolaVai(){
p = new Charmander();
}
public void setP(Pokemon p) {
this.p = p;
}
public void evolui(){
p.evolui(this);
}
public String pokemonSeuNome(){
return p.getNome();
}
public void ataque(){
p.ataque();
}
}
Classe Concreta
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package state;
/**
*
* @author toucatronic
*/
public class Charmander implements Pokemon{
String nome = "Charmander";
public String getNome() {
return nome;
}
public void evolui(Treinador t) {
t.setP(new Charmeleon());
}
@Override
public void ataque() {
System.out.println("Lança Chamas");
}
}