当前位置:网站首页>【Static proxy】
【Static proxy】
2022-08-10 05:11:00 【liangjiayy】
先看一个类:Thread
- 接口类Runnable:

- Thread 类实现了 Runnable

- 有一个Runnable的成员变量

- Constructor can be passedRunnable

- 实现Runnable的run方法,调用成员变量的run:

This is a static proxy.
Now implement a simple static proxy:
- There is an interface for cooking
- Chef implements the cooking interface
- Now want to do something before and after the chef cooks(It is equivalent to enhancing the chef's cooking method)
- Define a restaurant interface
- Prepare the ingredients before the chef cooks
- The food is served to the user after the chef has cooked it
具体代码如下:
public class Tests {
public static void main(String[] args) {
Hotel hotel = new Hotel(new Chef());
hotel.cook();
}
}
//做饭
interface Cooking {
void cook();
}
//厨师,just cook
class Chef implements Cooking {
@Override
public void cook() {
System.out.println("Chef 正在做饭...");
}
}
//饭店,准备食材、厨师做饭、Provide food to customers
class Hotel implements Cooking {
private Cooking cooking;
//The constructor passes in the interface object
public Hotel(Cooking cooking) {
this.cooking = cooking;
}
@Override
public void cook() {
//Enhancements to interface object methods
System.out.println("Hotel准备食材");
cooking.cook();
System.out.println("HotelProvide products to users");
}
}
边栏推荐
- Advanced Feature Selection Techniques in Linear Models - Based on R
- Big guys, mysql cdc (2.2.1 and previous versions) sometimes has this situation since savepoint, is there anything wrong?
- Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...
- awk of the Three Musketeers of Shell Programming
- Mysql CDC (2.1.1) inital snapshot database set up five concurrent degree, se
- 线程(下):读写者模型\环形队列\线程池
- What are the common commands of mysql
- 一篇文章掌握整个JVM,JVM超详细解析!!!
- 深度学习之-01
- oracle cdc时,设置并行度2插槽数1,最终任务只有一个tm,是不是因为oracle不支持并发
猜你喜欢

leetcode每天5题-Day10

干货 | 查资料利器:线上图书馆

LeetCode·124.二叉树中的最大路径和·递归

tensorflow分词深度学习——影评预测

Jenkins 如何玩转接口自动化测试?

细数国产接口协作平台的六把武器!

How to choose the right oscilloscope probe in different scenarios

2022 R2 transportable pressure vessel filling operation examination question bank simulation platform

Why are negative numbers in binary represented in two's complement form - binary addition and subtraction

如何从代码层提高产品质量
随机推荐
Stacks and Queues | Implementing Queues with Stacks | Implementing Stacks with Queues | Basic Theory and Code Principles
转型做产品,考NPDP靠谱吗?
strongest brain (1)
Thread.sleep, Thread.yield role explanation
summer preschool assignments
oracle rac 11g安装执行root.sh时报错
【裴蜀定理】CF1055C Lucky Days
二进制中负数为何要用补码形式来表示——二进制加减法
Zhongang Mining: Strong downstream demand for fluorite
How cursors work in Pulsar
一篇文章带你搞懂什么是幂等性问题?如何解决幂等性问题?
如何从代码层提高产品质量
aliases节点分析
小影科技IPO被终止:年营收3.85亿 五岳与达晨是股东
软考考生注意!2022年下半年报名详细流程来了!
conda创建虚拟环境方法和pqi使用国内镜像源安装第三方库的方法教程
基于BP神经网络的多因素房屋价格预测matlab仿真
Advanced Feature Selection Techniques in Linear Models - Based on R
Linear Algebra (4)
ThreadPoolExecutor线程池原理