装饰设计模式

使用装饰设计模式来对某个类中的功能进行增强
* 装饰设计模式
* Writer
* —TextWriter
* —Mp3Writer
* —Mp4Writer
* —BufferWriter(Writer out)
*
装饰设计模式在使用的时候,功能增强的类和其他需要增前的类一般都属于同一个父类或者接口
JavaWeb中的过滤器Filter,对源码的类的功能进行增强

class  people{ 
    public void eat(){
     System.out.println("直接剥皮");
    }
}  

class NewPeoson extends Person{
    public void eat () { 
        System.out.println("先洗一下...");
        System.out.println("生个火");
        super.eat();
        System.out.println("烤一下..");
        System.out.println("就着酒吃");
    }
}  

class student{ 
  private Person p ;
  public Student(Person p){
       this p = p ; 
  } 

public void eat(){ 
    System.out.println("先洗一下...");
    System.out.println("生个火");
    p.eat();
    System.out.println("烤一下..");
    System.out.println("就着酒吃");
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章