当前位置:网站首页>Static proxy of proxy mode
Static proxy of proxy mode
2022-07-07 02:47:00 【Xiaobai without work】
1: Static proxy concept
Wrap the object with a proxy object , Then replace the object with the proxy object ,
Any call to the original object must pass through the proxy object , Proxy object decision When Method to call the original object 【 Polymorphic features used ( Subclass references point to parent objects , When executing methods , Is the code that executes subclasses )】
2: Static proxy features
2.1: Fixed target role 【 It must be an object that implements the specified interface or class !!!】
2.2: Get the target role before the application executes
2.3: Proxy objects enhance the behavior of the target object
2.4: There may be multiple agents cause " Class blast "( shortcoming ) shortcoming : The proxy object and the target object need to implement the same interface
3: Code implementation
3.1: Write a common interface , Define the behavior method name
public interface Marry {
public void toMarry();
}
3.2: Define target object class , Implementation interface
/*** Static proxy ——> Target audience */
public class You implements Marry{
@Override
public void toMarry() {
System.out.println(" I'm getting married ");
}
}
3.3: Define proxy class , Implementation interface
/** * This agent , Only proxy can be implemented Marry Object of the interface */
public class MarryCompanyProxy implements Marry{
// Target audience
private Marry marry;
// The target object is passed in through the constructor
public MarryCompanyProxy(Marry marry) {
this.marry = marry;
}
@Override
public void toMarry() {
// Reinforcement behavior
before();
// Execute methods in the target object
marry.toMarry();
// Reinforcement behavior
after();
}
/*** Reinforcement behavior */
private void after() {
System.out.println(" Happy wedding , have a lovely baby early !");
}
/*** Reinforcement behavior */
private void before() {
System.out.println(" The site is being arranged ...");
}
}
3.4: Code testing
public class Test {
public static void main(String[] args) {
You you = new You();
MarryCompanyProxy marryCompanyProxy = new MarryCompanyProxy(you);
marryCompanyProxy.toMarry();
}
}
边栏推荐
- Difference and the difference between array and array structure and linked list
- CDB PDB user rights management
- 电气工程及其自动化
- 软件测试——Jmeter接口测试之常用断言
- Here comes a white paper to uncover the technology behind Clickhouse, a node with 10000 bytes!
- Hash table and full comments
- 压缩 js 代码就用 terser
- [leetcode]Search for a Range
- Summer Challenge database Xueba notes (Part 2)~
- 安德鲁斯—-多媒体编程
猜你喜欢

Derivative, partial derivative, directional derivative

Lombok makes the pit of ⽤ @data and @builder at the same time

Have fun | latest progress of "spacecraft program" activities

Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集

AWS学习笔记(一)

Apifox,你的API接口文档卷成这样了吗?

Redis入门完整教程:复制拓扑
MySQL提升大量数据查询效率的优化神器

3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP

慧通编程入门课程 - 2A闯关
随机推荐
MES管理系统的应用和好处有哪些
Redis入门完整教程:复制配置
Douban average 9 x. Five God books in the distributed field!
数论 --- 快速幂、快速幂求逆元
安全巡检的工作
运维管理系统有哪些特色
Fundamentals of process management
6-6漏洞利用-SSH安全防御
leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
unity webgl自适应网页尺寸
widerperson数据集转化为YOLO格式
Pgadmin4 of PostgreSQL graphical interface tool
用全连接+softmax对图片的feature进行分类
MySQL提升大量数据查询效率的优化神器
如何设计好接口测试用例?教你几个小技巧,轻松稿定
4--新唐nuc980 挂载initramfs nfs文件系统
3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP
基于ensp防火墙双击热备二层网络规划与设计
Application analysis of face recognition
你不可不知道的Selenium 8种元素定位方法,简单且实用