当前位置:网站首页>[designmode] proxy pattern

[designmode] proxy pattern

2022-07-07 16:36:00 weixin_ forty-three million two hundred and twenty-four thousan

Basic introduction

  1. The proxy pattern : Provide a surrogate for an object , To control access to this object . That is, access the target object through the proxy object . The advantage of this is : It can be realized on the basis of the target object , Enhance additional functional operations , That is, extending the functionality of the target object .

  2. The proxied object can be a remote object 、 Create expensive objects or objects that need security control

  3. There are different forms of agency , There are three main types Static proxy 、 The reason is A dynamic proxy (JDK agent 、 The interface agent ) and Cglib The reason is agent ( Objects can be created dynamically in memory , Instead of implementing interfaces , He belongs to the category of dynamic agency ) .

1 The proxy pattern (Proxy)

1.1 The basic introduction of agent mode

  1. The proxy pattern : Provide a surrogate for an object , To control access to this object . That is, access the target object through the proxy object . The advantage of this is : It can be realized on the basis of the target object , Enhance additional functional operations , That is, extending the functionality of the target object .

  2. The proxied object can be a remote object 、 Create expensive objects or objects that need security control

  3. There are different forms of agency , There are three main types Static proxy 、 The reason is A dynamic proxy (JDK agent 、 The interface agent ) and Cglib The reason is agent ( Objects can be created dynamically in memory , Instead of implementing interfaces , He belongs to the category of dynamic agency ) .

  4. Schematic diagram of agent mode

 Insert picture description here

2. Static proxy

2.1 The basic introduction of static code pattern

Static agents are used , You need to define an interface or parent class , Proxied object ( That is, the target object ) Implement the same interface or inherit the same parent class with the proxy object

原网站

版权声明
本文为[weixin_ forty-three million two hundred and twenty-four thousan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071416475094.html