package com.game.ThisTest;
/*
业务逻辑:在精灵宝可梦中,训练师可以将会使用泡沫光线的杰尼龟训练为
会使用火箭头槌的卡咪龟
*/
//训练家类:拥有将杰尼龟训练成为卡咪龟的职责
class Trainer{
public void practice(Zenigame zni){
zni.useSkill();//杰尼龟使用技能
zni.getEvolved().useSkill();//杰尼龟进化为卡咪龟后使用技能
}
}
//卡咪龟类。卡咪龟可以使用火箭头槌技能
class Wartotortle{
Wartotortle(Zenigame zni){
System.out.println("杰尼龟进化为卡咪龟");
}
void useSkill(){
System.out.println("卡咪龟,快使用火箭头槌!");
}
}
//在自然情况下,杰尼龟会进化为卡咪龟
class Nature{
static Wartotortle Evolution(Zenigame zni){
return new Wartotortle(zni);
}
}
//杰尼龟类,进化后会得到卡咪龟
class Zenigame{
Wartotortle getEvolved(){
return Nature.Evolution(this);//this表示传递杰尼龟对象
}
void useSkill(){
System.out.println("杰尼龟,快使用泡沫光线!");
}
}
public class Pokemon {
public static void main(String[] args) {
new Trainer().practice(new Zenigame());
}
}
原文:https://www.cnblogs.com/miaowulj/p/14493179.html