当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- SQL quick query
- 后缀表达式转中缀表达式
- 简明 VIM 练级攻略
- To introduce to you, this is my flow chart software—— draw.io
- API生命周期的5个阶段
- [200 interview experience], programmer interview, common interview questions analysis
- Solve the problem that the value of new date() of JS in IE and Firefox is invalid date and Nan Nan
- APReLU:跨界应用,用于机器故障检测的自适应ReLU | IEEE TIE 2020
- The interface testing tool eolinker makes post request
- 使用Fastai开发和部署图像分类器应用
猜你喜欢

经典动态规划:最长公共子序列

选择排序

Opencv solves the problem of ippicv download failure_ 2019_ lnx_ intel64_ general_ 20180723.tgz offline Download

The minimum insertion times of palindrome

进程 线程 协程

不是程序员,代码也不能太丑!python官方书写规范:任何人都该了解的 pep8

装饰器(一)

Select sort

Flink series (0) -- Preparation (basic stream processing)

AI人工智能编程培训学什么课程?
随机推荐
使用Fastai开发和部署图像分类器应用
C/C++知识分享: 函数指针与指针函数,看完这篇你还能不懂?
Opencv solves the problem of ippicv download failure_ 2019_ lnx_ intel64_ general_ 20180723.tgz offline Download
Constructors and prototypes
给大家介绍下,这是我的流程图软件 —— draw.io
Creating a text cloud or label cloud in Python
Implementation of warehouse management system with ABP (net core) + easyUI + efcore
选择API管理平台之前要考虑的5个因素
Newbe.ObjectVisitor Example 1
JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
go语言参数传递到底是传值还是传引用?
JVM真香系列:轻松理解class文件到虚拟机(上)
latex入门
[200 interview experience], programmer interview, common interview questions analysis
Newbe.ObjectVisitor 样例 1
【200人面试经验】,程序员面试,常见面试题解析
Is parameter passing in go language transfer value or reference?
不是程序员,代码也不能太丑!python官方书写规范:任何人都该了解的 pep8
Suffix expression to infix expression
如果把编程语言当武功绝学!C++是九阴真经,那程序员呢?