装饰设计模式

来源:互联网 发布:下载了软件打不开 编辑:程序博客网 时间:2024/05/29 07:38
package cn.mdln.demo;
/**
 * 装饰设计模式(组合)
 * @author Administrator
 *
 */
public class Demo8 {


public static void main(String[] args) {
Voice voice=new Voice(10);
voice.say();
EnlargeVoice en=new EnlargeVoice(10,voice);
en.say();


}


}
class Voice
{
private int voice;


public Voice(int voice) {
super();
this.voice = voice;
}


public int getVoice() {
return voice;
}


public void setVoice(int voice) {
this.voice = voice;
}
public void say()
{
System.out.println("原音量:"+getVoice());
}
}
class EnlargeVoice
{
private int enlargevoice;
private Voice voice;
public EnlargeVoice(int enlargevoice,Voice voice) {
this.enlargevoice=enlargevoice;
this.voice = voice;
}
public int getVoice() {
return enlargevoice;
}
public void setVoice(int enlargevoice) {
this. enlargevoice= enlargevoice;
}
public void say()
{
System.out.println("扩音器的音量:"+voice.getVoice()*100);
}
}
0 0
原创粉丝点击