当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢
使用Fastai开发和部署图像分类器应用
Newbe.ObjectVisitor Example 1
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
SQL quick query
选择API管理平台之前要考虑的5个因素
Mycat搭建
Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
动态规划答疑篇
线程池运用不当的一次线上事故
学会了volatile,你变心了,我看到了
随机推荐
Octave基本语法
How to deploy pytorch lightning model to production
PAT_甲级_1056 Mice and Rice
第五章
C/C++学习日记:原码、反码和补码
iptables从入门到掌握
中缀表达式转后缀表达式
C / C + + knowledge sharing: function pointer and pointer function, can you understand after reading this article?
API生命周期的5个阶段
国内三大云数据库测试对比
存储过程动态查询处理方法
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
为什么需要使用API管理平台
Swagger介绍和应用
深拷贝
Looking for better dynamic getter and setter solutions
Dynamic planning
Five factors to consider before choosing API management platform
JVM真香系列:轻松理解class文件到虚拟机(下)
.NET Core 跨平台资源监控库及 dotnet tool 小工具