zoukankan      html  css  js  c++  java
  • C++设计模式之-代理模式

    根据程洁的大话模式:

     1 // Proxy.cpp : 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include "stdafx.h"
     5 #include<iostream>
     6 #include <string>
     7 using namespace std;
     8 
     9 class Girl
    10 {
    11 public:
    12     Girl(string name = ""):mName(name){}
    13     string getName()
    14     {
    15         return mName;
    16     }
    17 private:
    18     string mName;
    19 };
    20 
    21 class GiveGift
    22 {
    23 public:
    24     virtual void GiveDolls() = 0;
    25     virtual void GiveFlowers() = 0;
    26     virtual void GiveChocolate() = 0;
    27 };
    28 
    29 class Puisuit:public GiveGift
    30 {
    31 public:
    32     Puisuit(Girl mm):mGirl(mm){}
    33     virtual void GiveDolls()
    34     {
    35         cout<<""<<mGirl.getName()<<"玩具"<<endl;
    36     }
    37     virtual void GiveFlowers()
    38     {
    39         cout<<""<<mGirl.getName()<<"鲜花"<<endl;
    40     }
    41     virtual void GiveChocolate()
    42     {
    43         cout<<""<<mGirl.getName()<<"巧克力"<<endl;
    44     }
    45 private:
    46     Girl mGirl;
    47 };
    48 
    49 class Proxy:public GiveGift
    50 {
    51 public:
    52     Proxy(Girl mm)
    53     {
    54         mPuisuit = new Puisuit(mm);
    55     }
    56     virtual void GiveDolls()
    57     {
    58         mPuisuit->GiveDolls();
    59     }
    60     virtual void GiveFlowers()
    61     {
    62         mPuisuit->GiveFlowers();
    63     }
    64     virtual void GiveChocolate()
    65     {
    66         mPuisuit->GiveChocolate();
    67     }
    68 private:
    69     Puisuit* mPuisuit;
    70 };
    71 int _tmain(int argc, _TCHAR* argv[])
    72 {
    73     cout<<"代理模式"<<endl;
    74     Girl girl("娇娇");
    75     Proxy pro(girl);
    76     pro.GiveDolls();
    77     pro.GiveFlowers();
    78     pro.GiveChocolate();
    79     system("pause");
    80     return 0;
    81 }
  • 相关阅读:
    手机号码正则表达式
    POJ 3233 Matrix Power Series 矩阵快速幂
    UVA 11468
    UVA 1449
    HDU 2896 病毒侵袭 AC自动机
    HDU 3065 病毒侵袭持续中 AC自动机
    HDU 2222 Keywords Search AC自动机
    POJ 3461 Oulipo KMP模板题
    POJ 1226 Substrings KMP
    UVA 1455 Kingdom 线段树+并查集
  • 原文地址:https://www.cnblogs.com/wxmwanggood/p/9272874.html
Copyright © 2011-2022 走看看