当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Dynamic query processing method of stored procedure
- Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
- Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
- Introduction and application of swagger
- 存储过程动态查询处理方法
- 动态规划答疑篇
- To introduce to you, this is my flow chart software—— draw.io
- latex入门
- 新手入坑指南:工作原因“重启”Deepin系统,发现真的香啊
- How to deploy pytorch lightning model to production
猜你喜欢
动态规划答疑篇
Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020
Learn volatile, you change your mind, I see
精通高并发与多线程,却不会用ThreadLocal?
新手入坑指南:工作原因“重启”Deepin系统,发现真的香啊
在Python中创建文字云或标签云
Proficient in high concurrency and multithreading, but can't use ThreadLocal?
Part I - Chapter 1 Overview
信息安全课程设计第一周任务(7条指令的分析)
opencv 解决ippicv下载失败问题ippicv_2019_lnx_intel64_general_20180723.tgz离线下载
随机推荐
PAT_ Grade A_ 1056 Mice and Rice
Constructors and prototypes
Problem solving templates for subsequence problems in dynamic programming
go语言参数传递到底是传值还是传引用?
net.sf.json . jsonobject's format processing of time stamp
Using fastai to develop and deploy image classifier application
Summary of interface test case ideas
JVM真香系列:轻松理解class文件到虚拟机(上)
Five design schemes of singleton mode
Octave基本语法
Part 1 - Chapter 2 pointer operation
Opencv solves the problem of ippicv download failure_ 2019_ lnx_ intel64_ general_ 20180723.tgz offline Download
文件拷贝的实现
Implementation of warehouse management system with ABP (net core) + easyUI + efcore
[cloud service] there are so many ECS instances on alicloud server, how to select the type? Best practice note
Not a programmer, code can't be too ugly! The official writing standard of Python: pep8 everyone should know
Development and deployment of image classifier application with fastai
【杂谈】JS相关的线程模型整理
abp(net core)+easyui+efcore实现仓储管理系统——出库管理之五(五十四)
信息安全课程设计第一周任务(7条指令的分析)