java 装饰设计模式

来源:互联网 发布:开源旅游cms 编辑:程序博客网 时间:2024/05/21 03:58
/*装饰设计模式当想要对已有的对象功能进行增强时,可以定义类,将已有的对象传入,基于已有的功能,并提供加强功能。那么自定义的该类称装饰类。*/class Person{public void chifan(){System.out.println("eat");}}class SuperPerson{private Person p;SuperPerson(Person p){this.p=p;}public void superChiFan(){System.out.println("hejiu");p.chifan();System.out.println("tiandian");}}class PersonStrongDemo {public static void main(String[] args) {Person p=new Person();SuperPerson sp=new SuperPerson(p);sp.superChiFan();p.chifan();}}

0 0