《Head First设计模式》读书笔记 -- (第一章)策略模式
?本文属贫僧不吃肉原创,欢迎转载,转载请注明来自 http://never-say-never.iteye.com/blog/851923
public abstract class Lady{Behavior behavior ; public void setBehavior(b){this.behavior=b;}public void show(){behavior.show();}public void smile(){System.out.println(“刷牙,姐一直用舒肤佳!”)}}
public class FengJie extends Lady{//定义凤姐类public FengJie(){behavior=new Merry();}
public class FuRong extends Lady{//定义芙蓉姐姐类public FuRong(){behavior=new Dance();}}
public interface Behavior{public void show();}
//定义结婚类public class Merry implements Behavior{public void show(){System.out.println(“人家只嫁给氢化烟酒僧~”);}}
//定义芙蓉姐姐的跳舞类~~public class Dance implements Behavior{public void show(){System.out.println(“姐不是巴黎欧莱雅,你不值得拥有”);}}
public class Test{public static void main(String[] args) { Lady fj = new FengJie(); //凤姐 lady fr = new FuRong(); //芙蓉姐姐 fj.show(); //小凤,秀一下fj.smile(); //小凤,笑一个 fr.show(); //芙蓉姐姐,秀一下fr.smile(); //芙蓉姐姐,笑一个}}
?
忘了贴输出结果,后来修改文章想加进去,发现格式全乱了。。没办法。。只能贴在后面了。。JE啊。。不给力啊~~~