当前位置:网站首页>装饰器(一)
装饰器(一)
2020-11-08 21:03:00 【8Years】
//装饰器的具体应用;
//例如,把一个声音扩大2倍
// 实现过程:1.声音的接口,2.人这个类,3.扩音器这个类
// 4.把人这个类传进扩音器这个类来,从而实现声音的扩大(所以扩音器里面要有一个构造器(用来传入人这个对象))
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("扩音器"+p.getVoice()*2);
}
}
}
输出结果 10 扩音器20
版权声明
本文为[8Years]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4583813/blog/4708092
边栏推荐
- 动态规划之子序列问题解题模板
- IT industry salary has been far ahead! Ten years later, is the programmer still a high paying profession?
- 第一部分——第2章指针操作
- If the programming language as martial arts unique! C++ is Jiu Yin Jing. What about programmers?
- ITerm2 配置和美化
- Flink系列(0)——准备篇(流处理基础)
- 给大家介绍下,这是我的流程图软件 —— draw.io
- How to deploy pytorch lightning model to production
- Five design schemes of singleton mode
- 接口测试工具Eolinker进行post请求
猜你喜欢

Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020

Using annotation + interceptor to implement asynchronous execution

Mongodb add delete modify query operation

Iptables from introduction to mastery

Creating a text cloud or label cloud in Python

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

Proficient in high concurrency and multithreading, but can't use ThreadLocal?

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

综合架构的简述

精通高并发与多线程,却不会用ThreadLocal?
随机推荐
【Elasticsearch 技术分享】—— 十张图带大家看懂 ES 原理 !明白为什么说:ES 是准实时的!
git操作与分支管理规范
CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
Tasks of the first week of information security curriculum design (analysis of 7 instructions)
Dynamic query processing method of stored procedure
经典动态规划:最长公共子序列
接口测试工具Eolinker进行post请求
opencv 解决ippicv下载失败问题ippicv_2019_lnx_intel64_general_20180723.tgz离线下载
单例模式的五种设计方案
微信小程序相关
使用Fastai开发和部署图像分类器应用
Newbe.ObjectVisitor Example 1
Opencv solves the problem of ippicv download failure_ 2019_ lnx_ intel64_ general_ 20180723.tgz offline Download
为什么需要使用API管理平台
【云服务】阿里云服务器ECS实例规格那么多,如何选型?最佳实践说明
net.sf.json.JSONObject对时间戳的格式化处理
Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
Python 列表的11个重要操作
C/C++学习日记:原码、反码和补码
experiment