proxy patter --代理模式
来源:互联网 发布:ai人工智能培训班 编辑:程序博客网 时间:2024/06/04 19:35
分类: 设计模式2013-01-11 09:55 229人阅读 评论(2) 收藏 举报
设计模式
wrapper:对接口编程,在保持接口不变的情况下,加入一些附加的功能比如 隐藏远程调用,
对于复杂的软件系统常常有一种处理手法,即增加一层间接层,从而使得系统获得一种更为灵活、满足特定需求的解决方案。在面向对象的系统中,有些对象由于某种原因,比如对象创建的开销很大,或者某些操作需要安全控制,或者需要进程外的访问等,直接访问会给使用者或者系统结构带来很多麻烦。
Proxy设计模式就是在不失去透明操作对象的同时,通过增加一层间接层来管理、控制这些对象特有的复杂性。
- // Proxy.h
- #include <string>
- #include <iostream>
- #include <string>
- class IEmployee
- {
- public:
- virtual string get_name(int ID) = 0;
- virtual int get_age(int ID) = 0;
- virtual double get_salary(int ID) = 0;
- public:
- virtual ~IEmployee();
- };
- IEmployee::~IEmployee()
- {
- cout << "in the destructor of IEmployee..." << endl;
- }
- class Employee : public IEmployee
- {
- public:
- string get_name(int ID);
- int get_age(int ID);
- double get_salary(int ID);
- ~Employee();
- };
- string Employee::get_name(int ID)
- {
- // ... 假定此处查询数据库,获得ID对应员工的姓名
- string name = "tom";
- return name;
- }
- int Employee::get_age(int ID)
- {
- // ... 假定此处查询数据库,获得ID对应员工的年龄
- int age = 20;
- return age;
- }
- double Employee::get_salary(int ID)
- {
- // ... 假定此处查询数据库,获得ID对应员工的工资
- double salary = 100000.00;
- return salary;
- }
- Employee::~Employee()
- {
- cout << "in the destructor of Employee..." << endl;
- }
- //代理
- class EmployeeProxy : public IEmployee
- {
- public:
- string get_name(int ID);
- int get_age(int ID);
- double get_salary(int ID);
- ~EmployeeProxy();
- };
- string EmployeeProxy::get_name(int ID)
- {
- // ...假定此处通过socket或者RPC等其他方式访问Employee中的get_name(int ID)方法,并接受相应的返回值
- string name = "tom";
- return name;
- }
- int EmployeeProxy::get_age(int ID)
- {
- // ...假定此处通过socket或者RPC等其他方式访问Employee中的get_age(int ID)方法,并接受相应的返回值
- int age = 20;
- return age;
- }
- double EmployeeProxy::get_salary(int ID)
- {
- // ...假定此处通过socket或者RPC等其他方式访问Employee中的get_salary(int ID)方法,并接受相应的返回值
- double salary = 100000.00;
- return salary;
- }
- EmployeeProxy::~EmployeeProxy()
- {
- cout << "in the destructor of EmployeeProxy..." << endl;
- }
- // Proxy.cpp
- #include "Proxy.h"
- int main(int argc, char **argv)
- {
- IEmployee *employee = new EmployeeProxy;
- cout << employee->get_name(10) << endl;
- cout << employee->get_age(10) << endl;
- cout << employee->get_salary(10) << endl;
- delete employee;
- return 0;
- }
- proxy patter --代理模式
- Proxy模式 代理模式
- 代理模式:Proxy模式
- 代理(Proxy)模式
- 代理模式Proxy Design
- 代理(Proxy)模式
- 代理(Proxy)模式
- 代理模式(Proxy Pattern)
- 代理(Proxy)模式
- 代理模式(Proxy Pattern)
- proxy(代理)模式
- Proxy Pattern (代理模式)
- Proxy pattern 代理模式
- 代理模式(Proxy)
- java 代理(proxy)模式
- Proxy 代理模式
- 代理模式(Proxy)
- 代理模式(Proxy pattern)
- Nmap扫描原理与用法
- ModelSim仿真流程
- 作为程序员,要取得非凡成就需要记住的15件事。
- Android 触摸屏(TP)问题现象分析和解决方法汇总
- finally在什么时候执行
- proxy patter --代理模式
- windows jenkins通过git获取代码
- java中指定小数点后面的位数
- Linus Torvalds - 从单链表中删除节点
- Linux下PCI设备驱动程序开发——总述
- DedeCMS系统安全检测功能使用说明
- Oracle数据库对象简介
- unicode,ansi,utf-8,unicode big endian编码的区别
- C语言文件操作