当前位置:网站首页>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();
}
}
边栏推荐
- Web3's need for law
- How to build a 32core raspberry pie cluster from 0 to 1
- HAVE FUN | “飞船计划”活动最新进展
- 【森城市】GIS数据漫谈(二)
- 实施MES管理系统时,哪些管理点是需要注意的
- [leetcode]Search for a Range
- fiddler的使用
- AWS learning notes (I)
- The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
- 【2022国赛模拟】多边形——计算几何、二分答案、倍增
猜你喜欢
Number theory --- fast power, fast power inverse element
Application analysis of face recognition
dotConnect for DB2数据提供者
慧通编程入门课程 - 2A闯关
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
C语言练习题_1
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
Cloud Mail .NET Edition
The 8 element positioning methods of selenium that you have to know are simple and practical
随机推荐
MySQL
Cloud Mail . NET Edition
Statistics of radar data in nuscenes data set
安德鲁斯—-多媒体编程
基于ensp防火墙双击热备二层网络规划与设计
Niuke programming problem -- double pointer of 101 must be brushed
Go swagger use
Hash table and full comments
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
Apifox, is your API interface document rolled up like this?
KYSL 海康摄像头 8247 h9 isapi测试
测试优惠券要怎么写测试用例?
MySQL --- 常用函数 - 字符串函数
MMDetection3D加载毫米波雷达数据
【森城市】GIS数据漫谈(二)
Code line breaking problem of untiy text box
unity 自定义webgl打包模板
wzoi 1~200
【Socket】①Socket技术概述
Rethinking of investment