设计模式学习——代理模式(Proxy Pattern)
放假啦~学生们要买车票回家了,有汽车票、火车票,等。但是,车站很远,又要考试,怎么办呢?找代理买啊,虽然要多花点钱,但是,说不定在搞活动,有折扣呢~

///
/// @file Selling_Tickets.h
/// @author marrs(chenchengxi993@gmail.com)
/// @date 2017-08-13 20:35:28
/// #ifndef __SELLING_TICKETS_H__
#define __SELLING_TICKETS_H__ #include <iostream> namespace marrs{ using std::cout;
using std::endl; class SellingTickets
{
public:
virtual ~SellingTickets(){} public:
virtual void Selling() = ;
virtual void Price() = ; }; } #endif // __SELLING_TICKETS_H__
///
/// @file Tickets.h
/// @author marrs(chenchengxi993@gmail.com)
/// @date 2017-08-13 20:39:17
/// #ifndef __TICKETS_H__
#define __TICKETS_H__ #include "Selling_Tickets.h" namespace marrs{ class Tickets
: public SellingTickets
{ }; } #endif // __TICKETS_H__
///
/// @file Bus_Ticket.h
/// @author marrs(chenchengxi993@gmail.com)
/// @date 2017-08-13 20:41:08
/// #ifndef __BUS_TICKET_H__
#define __BUS_TICKET_H__ #include "Tickets.h" namespace marrs{ class BusTicket
: public Tickets
{
public:
void Selling()
{
cout << "selling : BusTicket" << endl;
} void Price()
{
cout << "price : 80 RMB" << endl;
}
}; } #endif // __BUS_TICKET_H__
///
/// @file Train_Ticket.h
/// @author marrs(chenchengxi993@gmail.com)
/// @date 2017-08-13 20:41:08
/// #ifndef __TRAIN_TICKET_H__
#define __TRAIN_TICKET_H__ #include "Tickets.h" namespace marrs{ class TrainTicket
: public Tickets
{
public:
void Selling()
{
cout << "selling : TrainTicket" << endl;
} void Price()
{
cout << "price : 100 RMB" << endl;
}
}; } #endif // __TRAIN_TICKET_H__
///
/// @file Proxy.h
/// @author marrs(chenchengxi993@gmail.com)
/// @date 2017-08-13 20:46:13
/// #ifndef __PROXY_H__
#define __PROXY_H__ #include "Tickets.h" namespace marrs{ class Proxy
: public SellingTickets
{
public:
Proxy(Tickets * ticket)
: _ticket(ticket)
{
} ~Proxy()
{
delete _ticket;
} public:
void Selling()
{
_ticket->Selling();
} void Price()
{
_ticket->Price();
Proxy_Price();
Discount();
} private:
void Proxy_Price()
{
cout << "proxy price : 50 RMB" << endl;
} void Discount()
{
cout << "discount : 50%" << endl;
} private:
Tickets * _ticket; }; } #endif // __PROXY_H__
///
/// @file Student.cc
/// @author marrs(chenchengxi993@gmail.com)
/// @date 2017-08-13 20:51:42
/// #include "Proxy.h"
#include "Bus_Ticket.h"
#include "Train_Ticket.h" using namespace marrs; int main()
{
Proxy * proxy;
proxy = new Proxy(new BusTicket);
proxy->Selling();
proxy->Price();
delete proxy; proxy = new Proxy(new TrainTicket);
proxy->Selling();
proxy->Price();
delete proxy; return ;
}
编译,运行
[ccx@ubuntu ~/object-oriented/Proxy_Pattern]$>g++ * -o Tickets.exe
[ccx@ubuntu ~/object-oriented/Proxy_Pattern]$>./Tickets.exe
selling : BusTicket
price : RMB
proxy price : RMB
discount : %
selling : TrainTicket
price : RMB
proxy price : RMB
discount : %
设计模式学习——代理模式(Proxy Pattern)的更多相关文章
- 乐在其中设计模式(C#) - 代理模式(Proxy Pattern)
原文:乐在其中设计模式(C#) - 代理模式(Proxy Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 代理模式(Proxy Pattern) 作者:webabcd 介绍 为 ...
- 二十四种设计模式:代理模式(Proxy Pattern)
代理模式(Proxy Pattern) 介绍为其他对象提供一个代理以控制对这个对象的访问. 示例有一个Message实体类,某对象对它的操作有Insert()和Get()方法,用一个代理来控制对这个对 ...
- c#设计模式之代理模式(Proxy Pattern)
引言 代理这个词语,大家在现实世界已经频繁的接触过,例如火车站代理售票点,因为这些代理售票点的存在,我们不必要去火车站的售票处就可以查询或者取到火车票.代理点本身是没有能力生产车票的,我们在代理处享受 ...
- 乐在其中设计模式(C#) - 代理模式(Proxy Pattern)【转】
介绍 为其他对象提供一个代理以控制对这个对象的访问. 示例 有一个Message实体类,某对象对它的操作有Insert()和Get()方法,用一个代理来控制对这个对象的访问. MessageModel ...
- 设计模式系列之代理模式(Proxy Pattern)——对象的间接访问
说明:设计模式系列文章是读刘伟所著<设计模式的艺术之道(软件开发人员内功修炼之道)>一书的阅读笔记.个人感觉这本书讲的不错,有兴趣推荐读一读.详细内容也可以看看此书作者的博客https:/ ...
- 设计模式 - 代理模式(proxy pattern) 未使用代理模式 具体解释
代理模式(proxy pattern) 未使用代理模式 详细解释 本文地址: http://blog.csdn.net/caroline_wendy 部分代码參考: http://blog.csdn. ...
- 代理模式(Proxy pattern)
代理模式(proxy pattern):作用:为其他对象提供一种代理,以控制对这个对象的访问.代理对象在客户端对象和目标对象之间起中介的作用. 代理模式涉及到的角色: 抽象角色:声明真实对象和代理对象 ...
- 设计模式学习--迭代器模式(Iterator Pattern)和组合模式(Composite Pattern)
设计模式学习--迭代器模式(Iterator Pattern) 概述 ——————————————————————————————————————————————————— 迭代器模式提供一种方法顺序 ...
- 设计模式——代理模式(Proxy Pattern)
代理模式(Proxy),为其他对象提供一种代理以控制对这个对象的访问. UML图: 模型设计: Subject类: package com.cnblog.clarck; /** * Subject 类 ...
- 13.代理模式(Proxy Pattern)
using System; namespace Test { //抽象角色:声明真实对象和代理对象的共同接口. //代理角色:代理对象角色内部含有对真实对象的引用,从而可以操作真实对象, //同时代理 ...
随机推荐
- 一,PHP会话机制---cookie
1, 什么是会话 会话可简单理解为:用户打开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 2, cookie技术 cookie(小甜饼)是客户端技 ...
- poj2506 Tiling
http://poj.org/problem?id=2506 题目大意:用多少种方法可以用2*1或2*2瓦片来铺一个2*n的矩形? 这是一个2*17长方形的样品. 输入是一行行的序列,每一行包含一个整 ...
- ubuntu 中 mongodb 数据读写权限配置
首先,我们先对mongodb 数据库的权限做一点说明: 1 默认情况下,mongodb 没有管理员账号 2 只有在 admin 数据库中才能添加管理员账号并开启权限 3 用户只能在所在的数据库中登录, ...
- nginx请求频率限制模块ngx_http_limit_req_module
模块: ngx_http_limit_req_module 作用: 限制客户端请求频率,防止恶意攻击 配置示例: http { limit_req_zone $binary_remote_addr z ...
- MVC Filter中加入验证并跳转
public class BuildingFilter : ActionFilterAttribute { /// <summary> /// 验证 Building Cookie add ...
- 为autoLayout 增加标识符,方便调试
 如上图,是一个十分简单的布局. root view 上加了一个 button 和一个 webview. 不加标识符的样子 视图层级中没有标识  只有 UIView.WKWebView 之类,如果 ...
- Supporting Right-to-Left Languages
For the most part iOS supports Right-to-Left (RTL) languages such as Arabic with minimal developer e ...
- POJ 2253
#include<iostream> #include<stdio.h> #include<math.h> #include<iomanip> #def ...
- AsyncTask、HandlerThread、IntentService和线程池
AsyncTask AsyncTask 是一种轻量级的异步任务类,可以在线程池中执行后台任务,然后把执行的进度和最终结果传递给主线程用于更新UI. 可以直接继承AsyncTask,在类中实现异步操作, ...
- HUE配置文件hue.ini 的yarn_clusters模块详解(图文详解)(分HA集群和非HA集群)
不多说,直接上干货! 我的集群机器情况是 bigdatamaster(192.168.80.10).bigdataslave1(192.168.80.11)和bigdataslave2(192.168 ...