当前位置:网站首页>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.
边栏推荐
- MySQL installation and configuration
- Qt发布多语言国际化翻译
- C实现贪吃蛇小游戏
- Notes and notes
- AWT common components, FileDialog file selection box
- Learning multi-level structural information for small organ segmentation
- QT QTableWidget 表格列置顶需求的思路和代码
- 配置交叉编译工具链和环境变量
- C language exercises (recursion)
- Practical gadget instructions
猜你喜欢
Experience weekly report no. 102 (July 4, 2022)
AWT introduction
JSON Web Token----JWT和传统session登录认证对比
Kubernets first meeting
Take you to quickly learn how to use qsort and simulate qsort
Cloud native - SSH article that must be read on the cloud (commonly used for remote login to ECS)
C语言练习题(递归)
My NVIDIA developer journey - optimizing graphics card performance
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
How to solve the component conflicts caused by scrollbars in GridView
随机推荐
LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
[microservice] Nacos cluster building and loading file configuration
剑指 Offer II 038. 每日温度
Learning multi-level structural information for small organ segmentation
QT 获取随机颜色值设置label背景色 代码
Notes and notes
Arcpy 利用updatelayer函数改变图层的符号系统
AWT常用组件、FileDialog文件选择框
Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
安装 Pytorch geometric
雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
JS arguments parameter usage and explanation
How to use multithreading to export excel under massive data? Source code attached!
Qt发布多语言国际化翻译
如何实现视频平台会员多账号登录
Bicolor case
The solution of win11 taskbar right click without Task Manager - add win11 taskbar right click function
Invalid revision: 3.18.1-g262b901-dirty
Learning multi-level structural information for small organ segmentation
24 magicaccessorimpl can access the debugging of all methods