当前位置:网站首页>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();
}
}
边栏推荐
- 测试优惠券要怎么写测试用例?
- Fundamentals of process management
- unity 自定义webgl打包模板
- Error in fasterxml tostringserializerbase
- Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
- Pgadmin4 of PostgreSQL graphical interface tool
- Remember the problem analysis of oom caused by a Jap query
- MySQL
- Go swagger use
- [leetcode]Search for a Range
猜你喜欢
Fundamentals of process management
Dotconnect for DB2 Data Provider
C语言练习题_1
基于ensp防火墙双击热备二层网络规划与设计
6-6漏洞利用-SSH安全防御
【Socket】①Socket技术概述
MES管理系统的应用和好处有哪些
Huitong programming introductory course - 2A breakthrough
巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
How to write test cases for test coupons?
随机推荐
This week's hot open source project!
NuScenes数据集关于Radar数据的统计
Planning and design of double click hot standby layer 2 network based on ENSP firewall
Classify the features of pictures with full connection +softmax
Remember the problem analysis of oom caused by a Jap query
4--新唐nuc980 挂载initramfs nfs文件系统
写作系列之contribution
Software testing -- common assertions of JMeter interface testing
慧通编程入门课程 - 2A闯关
MySQL
人脸识别应用解析
C#/VB.NET 删除Word文档中的水印
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
A new path for enterprise mid Platform Construction -- low code platform
牛客编程题--必刷101之双指针篇
Apifox, is your API interface document rolled up like this?
Apifox,你的API接口文档卷成这样了吗?
Contribution of Writing Series
C语言练习题_1
Work of safety inspection