当前位置:网站首页>Decorator (1)
Decorator (1)
2020-11-08 21:03:00 【8Years】
// The specific application of decorators ;
// for example , Amplify a voice 2 times
// Implementation process :1. Voice interface ,2. Human beings ,3. The microphone class
// 4. Pass the human class into the microphone class , So that the sound can be amplified ( So there's a constructor in the loudspeaker ( It's used to introduce people into this object ))
public class testDerector {
public static void main(String[] args) {
Person p= new Person();
p.say();
Amplifile amplifile=new Amplifile(p);
amplifile.say();
}
interface Say {
void say();
}
public static 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(int voice) {
this.voice = voice;
}
}
static class Amplifile implements Say{
private Person p;
public Amplifile(Person p) {
this.p = p;
}
@Override
public void say() {
System.out.println(" Loudspeakers "+p.getVoice()*2);
}
}
}
Output results 10 Loudspeakers 20
版权声明
本文为[8Years]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢
随机推荐
接口测试用例思路总结
AI人工智能编程培训学什么课程?
Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
Wechat applet related
Creating a text cloud or label cloud in Python
第一部分——第2章指针操作
net.sf.json . jsonobject's format processing of time stamp
解决go get下载包失败问题
Newbe.ObjectVisitor Example 1
How to deploy pytorch lightning model to production
如何将 PyTorch Lightning 模型部署到生产中
选择排序
新手入坑指南:工作原因“重启”Deepin系统,发现真的香啊
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
Django's simple user system (3)
To introduce to you, this is my flow chart software—— draw.io
abp(net core)+easyui+efcore实现仓储管理系统——出库管理之五(五十四)
VirtualBox安装centos7
Come and have a look! What is the relationship between AQS and countdownlatch?
深拷贝







