当前位置:网站首页>【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");
}
}
边栏推荐
- Rpc interface stress test
- Become a language that hackers have to learn. Do you think it's okay after reading it?
- SQLSERVER 2008 解析 Json 格式数据
- Promise原理及实现
- openvino 安装(01)
- aliases节点分析
- 应用在智能触摸遥控器中的触摸芯片
- Unity implements UI edge detection and drag-and-drop functions
- 【论文笔记】Prototypical Contrast Adaptation for Domain Adaptive Semantic Segmentation
- 【u-boot】u-boot驱动模型分析(02)
猜你喜欢

万字总结:分布式系统的38个知识点

【静态代理】

Zhongang Mining: Strong downstream demand for fluorite

MySQL使用简单教程

leetcode每天5题-Day11

How to choose the right oscilloscope probe in different scenarios

暑期学前作业

Flutter开发:报错The following assertion was thrown resolving an image codec:Unable to…的解决方法

【LeetCode】41. The first missing positive number

Pulsar中游标的工作原理
随机推荐
ORA-16018 异常处理记录
暑期学前作业
大佬们,运行cdc后oracle归档日志20分钟增长3G是正常现象吗
Stacks and Queues | Implementing Queues with Stacks | Implementing Stacks with Queues | Basic Theory and Code Principles
告诉你如何从keil工程知道使用了多少RAM和ROM空间
2022 T Elevator Repair Exam Questions and Mock Exams
万字总结:分布式系统的38个知识点
2022 security officer C certificate test and simulation test in shandong province
flex related
二进制中负数为何要用补码形式来表示——二进制加减法
【LeetCode】41、 缺失的第一个正数
FPGA工程师面试试题集锦1~10
开发智能硬件过程中需要掌握的方法之经典
SQLSERVER 2008 parses data in Json format
aliases节点分析
小影科技IPO被终止:年营收3.85亿 五岳与达晨是股东
leetcode每天5题-Day12
成为黑客不得不学的语言,看完觉得你们还可吗?
什么是“大小端字节序”存储模式?
Joomla vulnerability reproduced