当前位置:网站首页>7. Agency mode
7. Agency mode
2022-07-04 06:20:00 【Muzi's day and night】
package proxyPattern;
import sun.net.www.content.image.gif;
/**
* Common implementation
*
* scene : tom know dany dany Meet Lily however tom I don't know Lily however however tom I want to go after lily Just want to give lily a present
*
* @author LiMing E-mail:[email protected]
* @date 2017 year 6 month 11 Japan Afternoon 7:44:03
*/
public class Commonly {
public static void main(String[] args) {
Girl girl = new Girl(" lily ");
Pursuit tom = new Pursuit(girl); // There's a problem here tom I don't know Lily Not directly accessible
// Send roses
tom.giveRose();
//
}
}
// handsome guy
class Pursuit {
Girl girl;
public Pursuit(Girl girl) {
this.girl = girl;
}
public void giveRose(){
System.out.println(" send "+girl.name+" Rose ");
}
public void giveLollipop(){
System.out.println(" send "+girl.name+" lollipop ");
}
}
// Cool mushroom
class Girl {
String name;
public Girl() {
}
public Girl(String name) {
this.name = name;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
package proxyPattern;
/**
* The proxy pattern The proxy pattern : Provides a proxy for other objects to control access to this object
*
*
* Remote agent :
* To provide local representation of an object in different address spaces . This hides the fact that an object exists in different address spaces (webService )
* The remote proxy provides a local representation object for an object located in a different address space , This different address space can be in this machine ,
* It can also be in another machine , Remote agent has a cool name : Ambassador .
* Local applications -》 Local agent -》 Server agent -》 Remote services
*
* Virtual agent :
* Create expensive objects as needed . It takes a long time to store objects through her ( For example, when a web page loads an image, it uses an object to store the address and name of the image But don't load pictures in time )
*
* Security agent :
* It is used to control the access rights of real objects ( Objects have different access rights )
*
* Smart agents :
* Intelligent guidance When calling real objects Agents deal with other things
*
* other xx agent Welcome to add Correction and correction
* @author LiMing E-mail:[email protected]
* @date 2017 year 6 month 11 Japan Afternoon 7:43:35
*/
public class ProxyPattern {
public static void main(String[] args) {
Girls girls = new Girls(" lily ");
//tom
Pursuits pursuits = new Pursuits(girls);
//dany
Proxy proxy = new Proxy(pursuits);
// Send lollipops
proxy.giveLollipops();
}
}
// Give gifts
interface IGiveGift {
abstract public void giveRoses();
abstract public void giveLollipops();
}
class Pursuits implements IGiveGift {
Girls girls;
public Pursuits(Girls girls) {
this.girls = girls;
}
public void giveRoses() {
System.out.println(" send " + girls.name + " Rose ");
}
public void giveLollipops() {
System.out.println(" send " + girls.name + " lollipop ");
}
}
// proxy class
class Proxy implements IGiveGift {
Pursuits pursuits;
public Proxy() {
}
public Proxy(Pursuits pursuits) {
this.pursuits = pursuits;
}
public void giveRoses() {
pursuits.giveRoses();
}
public void giveLollipops() {
pursuits.giveLollipops();
}
}
// Cool mushroom
class Girls {
String name;
public Girls() {
}
public Girls(String name) {
this.name = name;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
边栏推荐
- Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
- Tutle clock improved version
- 我的NVIDIA开发者之旅——优化显卡性能
- [March 3, 2019] MAC starts redis
- 手动对list进行分页(参数list ,当前页,页面大小)
- Weekly summary (*63): about positive energy
- How to implement lazy loading in El select (with search function)
- JS get the attribute values nested in the object
- How to determine whether an array contains an element
- Learning multi-level structural information for small organ segmentation
猜你喜欢
198. House raiding
740. Delete and get points
注释与注解
Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout
How to get the parent node of all nodes in El tree
509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
Learning multi-level structural information for small organ segmentation
Design and implementation of redis 7.0 multi part AOF
gslb(global server load balance)技术的一点理解
C语言练习题(递归)
随机推荐
Steady! Huawei micro certification Huawei cloud computing service practice is stable!
Distributed cap theory
4G wireless all network solar hydrological equipment power monitoring system bms110
C实现贪吃蛇小游戏
Review | categories and mechanisms of action of covid-19 neutralizing antibodies and small molecule drugs
[untitled]
Leakage detection relay jy82-2p
AWT常用组件、FileDialog文件选择框
C language exercises (recursion)
Understanding of cross domain and how to solve cross domain problems
QT 获取随机颜色值设置label背景色 代码
Native Cloud - SSH articles must be read on Cloud (used for Remote Login to Cloud Server)
How to expand all collapse panels
Sleep quality today 78 points
How to realize multi account login of video platform members
SQL join, left join, right join usage
Invalid revision: 3.18.1-g262b901-dirty
C语言中的函数(详解)
Gridview出现滚动条,组件冲突,如何解决
微信小程序使用rich-text中图片宽度超出问题