当前位置:网站首页>装饰器(一)
装饰器(一)
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
边栏推荐
- PAT_甲级_1056 Mice and Rice
- The minimum insertion times of palindrome
- 信息安全课程设计第一周任务(7条指令的分析)
- Come and have a look! What is the relationship between AQS and countdownlatch?
- 解决IE、firefox浏览器下JS的new Date()的值为Invalid Date、NaN-NaN的问题
- VirtualBox install centos7
- 解决go get下载包失败问题
- 第一部分——第2章指针操作
- CMS garbage collector
- Exercise 5
猜你喜欢

Dynamic relu: Microsoft's refreshing device may be the best relu improvement | ECCV 2020

Development and deployment of image classifier application with fastai

快来看看!AQS 和 CountDownLatch 有怎么样的关系?
![[200 interview experience], programmer interview, common interview questions analysis](/img/fb/625e17f83f6be064f7387e78ec082a.jpg)
[200 interview experience], programmer interview, common interview questions analysis

微信小程序相关

git操作与分支管理规范

Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19

Creating a text cloud or label cloud in Python

线程池运用不当的一次线上事故

JVM Zhenxiang series: easy understanding of class files to virtual machines (Part 2)
随机推荐
中缀表达式转后缀表达式
VirtualBox install centos7
Five design schemes of singleton mode
How to deploy pytorch lightning model to production
线程池运用不当的一次线上事故
RSA非对称加密算法
Countdownlatch explodes instantly! Based on AQS, why can cyclicbarrier be so popular?
Chapter five
Flink series (0) -- Preparation (basic stream processing)
IT industry salary has been far ahead! Ten years later, is the programmer still a high paying profession?
如何将PyTorch Lightning模型部署到生产中
Proficient in high concurrency and multithreading, but can't use ThreadLocal?
信息安全课程设计第一周任务(7条指令的分析)
选择API管理平台之前要考虑的5个因素
进程 线程 协程
getBytes之 LengthFieldBasedFrameDecoder服务端解析
Process thread coroutine
.NET Core 跨平台资源监控库及 dotnet tool 小工具
VirtualBox安装centos7
使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性