当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢

Programmers should know the URI, a comprehensive understanding of the article

The interface testing tool eolinker makes post request

第五章

都说程序员钱多空少,程序员真的忙到没时间回信息了吗?

To introduce to you, this is my flow chart software—— draw.io

Array acquaintance

C / C + + knowledge sharing: function pointer and pointer function, can you understand after reading this article?

Flink系列(0)——准备篇(流处理基础)

Creating a text cloud or label cloud in Python

选择排序
随机推荐
If the programming language as martial arts unique! C++ is Jiu Yin Jing. What about programmers?
第一部分——第2章指针操作
Dynamic planning
Part I - Chapter 1 Overview
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
npm install 无响应解决方案
CMS garbage collector
The interface testing tool eolinker makes post request
实现图片的复制
Case analysis of entitycore framework
Newbe.ObjectVisitor Example 1
寻找性能更优秀的动态 Getter 和 Setter 方案
Dynamic query processing method of stored procedure
Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
RSA非对称加密算法
国内三大云数据库测试对比
Learn volatile, you change your mind, I see
动态规划答疑篇
MYCAT build
Flink series (0) -- Preparation (basic stream processing)