/**
* p15 装饰器设计模式
*节点流:直接与数据源打交道(数组,文件),
*处理流:装饰器设计模式
*装饰器设计模式 :面向对象;
*/
/**
* 实现放大器对声音的放大动能
*
*/
public class FileUtils {
public void main(String[] args){
Person p = new Person();
p.say();
//装饰-装饰声音
Amplifier am = new Amplifier(p);
am.say();
}
}
interface Say{
void say();
}
class Person implements Say{
private int voice=10;
@Override
public void say(){
System.out.println("人的声音为:" + this.getVoice());
}
public int getVoice(){
return voice;
}
public void setVoice(){
this.voice = voice;
}
}
class Amplifier implements Say{
private int voice=10;
private Person p;
Amplifier(Person p){
this.p=p;
}
@Override
public void say(){
System.out.println("人的声音为:" + p.getVoice()*100);
}
}