class Person{ //装饰设计模式 //第一步都要维护同一个要扩展的类的方法 //第二步继承同一个父类 public String paly(){ return "一个画画的流程"; } } class Sun extends Person{ Person p; public Sun(Person p) { this.p=p; } @Override public String paly() { String string=p.paly(); string+="儿子画画"; return string; } } class Mo extends Person{ Person p; public Mo(Person p) { this.p=p; } @Override public String paly() { String string=p.paly(); string+="妈妈上色"; return string; } } class Ba extends Person{ Person p; public Ba(Person p) { this.p=p; } @Override public String paly() { String string=p.paly(); string+="爸爸装裱"; return string; } } public class Work1 { /** * @param args */ public static void main(String[] args) { Person p= new Person(); Sun sun=new Sun(p); Mo mo=new Mo(sun); Ba ba=new Ba(mo); System.out.println(ba.paly()); } }