当前位置:网站首页>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();
}
}
边栏推荐
- What are the characteristics of the operation and maintenance management system
- KYSL 海康摄像头 8247 h9 isapi测试
- Fundamentals of process management
- Draco - gltf model compression tool
- 安德鲁斯—-多媒体编程
- Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
- Code line breaking problem of untiy text box
- How to build a 32core raspberry pie cluster from 0 to 1
- What management points should be paid attention to when implementing MES management system
- The panel floating with the mouse in unity can adapt to the size of text content
猜你喜欢

Linear list --- circular linked list

Summer Challenge database Xueba notes (Part 2)~

unity中跟随鼠标浮动的面板,并可以自适应文字内容的大小

fiddler的使用

3--新唐nuc980 kernel支持jffs2, Jffs2文件系统制作, 内核挂载jffs2, uboot网口设置,uboot支持tftp

What management points should be paid attention to when implementing MES management system

Number theory --- fast power, fast power inverse element

Integerset of PostgreSQL

Five reasons for clothing enterprises to deploy MES management system

如何设计好接口测试用例?教你几个小技巧,轻松稿定
随机推荐
MySQL - common functions - string functions
CSDN summer camp course project analysis
Use of pgpool II and pgpooladmin
Safety delivery engineer
MySQL --- 常用函数 - 字符串函数
Halcon instance to opencvsharp (C openCV) implementation -- bottle mouth defect detection (with source code)
所谓的消费互联网仅仅只是做行业信息的撮合和对接,并不改变产业本身
A new path for enterprise mid Platform Construction -- low code platform
软件测试——Jmeter接口测试之常用断言
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
Web3's need for law
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
人脸识别应用解析
数论 --- 快速幂、快速幂求逆元
6-6 vulnerability exploitation SSH security defense
安全交付工程师
leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
MySQL
Integerset of PostgreSQL
Number theory --- fast power, fast power inverse element