当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 进程 线程 协程
- 200 programmers interview experience, all here
- Not a programmer, code can't be too ugly! The official writing standard of Python: pep8 everyone should know
- Django之简易用户系统(3)
- Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
- Dynamic query processing method of stored procedure
- [200 interview experience], programmer interview, common interview questions analysis
- 如果把编程语言当武功绝学!C++是九阴真经,那程序员呢?
- 信息安全课程设计第一周任务(7条指令的分析)
- C / C + + learning diary: original code, inverse code and complement code
猜你喜欢

ITerm2 配置和美化

iptables从入门到掌握

使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性

200人的程序员面试经验,都在这里了

解决go get下载包失败问题

Using annotation + interceptor to implement asynchronous execution

Implementation of warehouse management system with ABP (net core) + easyUI + efcore

Why need to use API management platform

线程池运用不当的一次线上事故

Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
随机推荐
寻找性能更优秀的动态 Getter 和 Setter 方案
CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
RSA asymmetric encryption algorithm
Suffix expression to infix expression
Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
Leetcode 45 jumping game II
VirtualBox安装centos7
To introduce to you, this is my flow chart software—— draw.io
WordPress网站程序和数据库定时备份到七牛云图文教程
CMS garbage collector
CMS垃圾收集器
快来看看!AQS 和 CountDownLatch 有怎么样的关系?
动态规划答疑篇
The minimum insertion times of palindrome
Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
Come and have a look! What is the relationship between AQS and countdownlatch?
[200 interview experience], programmer interview, common interview questions analysis
深拷贝
构造函数和原型
PAT_甲级_1056 Mice and Rice