当前位置:网站首页>The bottom implementation principle of thread - static agent mode
The bottom implementation principle of thread - static agent mode
2022-04-23 06:01:00 【hanyc..】
Static proxy :
- The names and parameters of real methods and proxy methods are the same , The method body is different ,
- The proxy class and the proxy class establish a relationship by implementing the same interface
- Proxy object (WeddingCompany The object of ) To delegate real objects (You The object of )
Advantages of static agents :
- Proxy objects can do a lot of things that real objects can't
- Real objects focus on doing their own things
package creatthread;
public class StaticProxy {
public static void main(String[] args) {
System.out.println(" Static proxy demo :");
You person = new You();
// Go to WeddingCompany Throw one of the constructors to realize Marry The object of
WeddingCompany wc = new WeddingCompany(person);
wc.happyMarry();
System.out.println();
System.out.println(" The embodiment of static agent in thread :");
// Go to Thread Throw one of the constructors to realize Runnable Object of the interface
Thread thread = new Thread(() -> System.out.println("you get married."));
thread.start();
}
}
// Public interface
interface Marry {
void happyMarry();
}
// Surrogate class
class You implements Marry {
@Override
public void happyMarry() {
System.out.println("you get married.");
}
}
// proxy class
class WeddingCompany implements Marry {
// Real object
private Marry person;
public WeddingCompany(Marry person) {
this.person = person;
}
// Functions that need to be completed by the proxy class itself , Call the method with the object of the proxy class inside the method
@Override
public void happyMarry() {
beforeMarry();
person.happyMarry();
afterMarry();
}
private void beforeMarry() {
System.out.println(" Set up the venue ");
}
private void afterMarry() {
System.out.println(" Remove the venue layout ");
}
}
result :

版权声明
本文为[hanyc..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230541159319.html
边栏推荐
- Custom exception class
- 自動控制(韓敏版)
- Chapter 4 of line generation - linear correlation of vector systems
- Manually delete registered services on Eureka
- 解决报错:ImportError: IProgress not found. Please update jupyter and ipywidgets
- SQL基础:初识数据库与SQL-安装与基本介绍等—阿里云天池
- String notes
- Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
- Protected (members modified by protected are visible to this package and its subclasses)
- RedHat6之smb服务访问速度慢解决办法记录
猜你喜欢

String notes

Pytorch学习记录(五):反向传播+基于梯度的优化器(SGD,Adagrad,RMSporp,Adam)

Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising

Filebrowser realizes private network disk

数字图像处理基础(冈萨雷斯)一

Conda 虚拟环境管理(创建、删除、克隆、重命名、导出和导入)

深入理解去噪论文——FFDNet和CBDNet中noise level与噪声方差之间的关系探索

Pytorch——数据加载和处理

Pyqt5 learning (I): Layout Management + signal and slot association + menu bar and toolbar + packaging resource package

Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving
随机推荐
数字图像处理基础(冈萨雷斯)二:灰度变换与空间滤波
线性代数第二章-矩阵及其运算
The user name and password of users in the domain accessing the samba server outside the domain are wrong
Pytorch learning record (IV): parameter initialization
MySql基础狂神说
Viewer: introduce MySQL date function
Configure domestic image accelerator for yarn
Shansi Valley P290 polymorphism exercise
Protected (members modified by protected are visible to this package and its subclasses)
去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
自動控制(韓敏版)
Linear algebra Chapter 2 - matrices and their operations
On traversal of binary tree
Fact final variable and final variable
Pytorch learning record (III): structure of neural network + using sequential and module to define the model
域内用户访问域外samba服务器用户名密码错误
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
编写一个自己的 RedisTemplate
字符串(String)笔记
umi官网yarn create @umijs/umi-app 报错:文件名、目录名或卷标语法不正确