当前位置:网站首页>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();
}
}
边栏推荐
- PCL 常用拟合模型及使用方法
- The panel floating with the mouse in unity can adapt to the size of text content
- Remember the problem analysis of oom caused by a Jap query
- 你不可不知道的Selenium 8种元素定位方法,简单且实用
- MySQL --- 常用函数 - 字符串函数
- B站6月榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
- This week's hot open source project!
- CSDN 夏令营课程 项目分析
- 数论 --- 快速幂、快速幂求逆元
- ODBC database connection of MFC windows programming [147] (with source code)
猜你喜欢

Have fun | latest progress of "spacecraft program" activities

B站6月榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!

Redis入门完整教程:复制配置

Compress JS code with terser

Application analysis of face recognition

如何设计好接口测试用例?教你几个小技巧,轻松稿定

压缩 js 代码就用 terser

Ali yunyili: how does yunyuansheng solve the problem of reducing costs and improving efficiency?

C#/VB.NET 删除Word文档中的水印

KYSL 海康摄像头 8247 h9 isapi测试
随机推荐
记一次JAP查询导致OOM的问题分析
MySQL
NuScenes数据集关于Radar数据的统计
Niuke programming problem -- double pointer of 101 must be brushed
Django数据库(SQlite)基本入门使用教程
Linear list --- circular linked list
C语言练习题_1
unity webgl自适应网页尺寸
Error in fasterxml tostringserializerbase
widerperson数据集转化为YOLO格式
Redis入门完整教程:问题定位与优化
写作系列之contribution
Redis入门完整教程:复制配置
Work of safety inspection
S120驱动器基本调试步骤总结
Difference and the difference between array and array structure and linked list
Cloud Mail .NET Edition
运维管理系统有哪些特色
This week's hot open source project!
Have fun | latest progress of "spacecraft program" activities