当前位置:网站首页>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();
}
}
边栏推荐
- MySQL提升大量数据查询效率的优化神器
- Code debugging core step memory
- 软件测试——Jmeter接口测试之常用断言
- 测试优惠券要怎么写测试用例?
- fasterxml ToStringSerializerBase报错
- Lombok makes the pit of ⽤ @data and @builder at the same time
- 数论 --- 快速幂、快速幂求逆元
- QT common Concepts-1
- Five reasons for clothing enterprises to deploy MES management system
- [leetcode]Search for a Range
猜你喜欢
unity 自定义webgl打包模板
Wireshark installation
LeetCode 77:组合
记一次JAP查询导致OOM的问题分析
Redis入门完整教程:复制配置
Draco - gltf model compression tool
Matlb| economic scheduling with energy storage, opportunity constraints and robust optimization
Summer Challenge database Xueba notes (Part 2)~
测试优惠券要怎么写测试用例?
Summary of basic debugging steps of S120 driver
随机推荐
Redis入门完整教程:问题定位与优化
人脸识别应用解析
Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
3--新唐nuc980 kernel支持jffs2, Jffs2文件系统制作, 内核挂载jffs2, uboot网口设置,uboot支持tftp
unity webgl自适应网页尺寸
巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
【Socket】①Socket技术概述
Qpushbutton- "function refinement"
Electrical engineering and automation
Digital scrolling increases effect
Oracle中日期的使用方法实例
Overall query process of PostgreSQL
Cloud Mail .NET Edition
Cloud Mail . NET Edition
CSDN summer camp course project analysis
【2022国赛模拟】多边形——计算几何、二分答案、倍增
Argo workflows source code analysis
Redis入门完整教程:复制配置
The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
LeetCode 77:组合