zoukankan      html  css  js  c++  java
  • 代理模式

    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    // 定义女人
    class KindWomen{
    public:
        virtual void MakeEyesWithMan() = 0;
        virtual void HappyWithMan() = 0;
    };
    
    // 定义潘金莲
    class PanJinLian : public KindWomen
    {
    public:
        virtual void MakeEyesWithMan()
        {
            cout << "潘金莲抛媚眼" << endl;
        }
    
        virtual void HappyWithMan()
        {
            cout << "潘金莲在和男人做那个....." << endl;
        }
    };
    
    // 定义贾氏
    class JiaShi : public KindWomen
    {
    public:
        virtual void MakeEyesWithMan()
        {
            cout << "贾氏抛媚眼" << endl;
        }
    
        virtual void HappyWithMan()
        {
            cout << "贾氏在和男人做那个....." << endl;
        }
    };
    
    // 王婆年老色衰,不能啪啪啪了
    class WangPo : public KindWomen
    {
    private:
        KindWomen *m_pWomen;
    
    public:
        WangPo()
        {
            m_pWomen = new PanJinLian();
        }
    
        WangPo(KindWomen *p)
        {
            m_pWomen = p;
        }
    
        ~WangPo()
        {
            if (m_pWomen != nullptr)
            {
                delete m_pWomen;
            }
        }
    
        virtual void MakeEyesWithMan()
        {
            m_pWomen->MakeEyesWithMan();
        }
    
        virtual void HappyWithMan()
        {
            m_pWomen->HappyWithMan();
        }
    };
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        cout << "西门庆色心起" << endl;
    
        cout << "王婆为西门庆和潘金莲搭桥" << endl;
    
        WangPo *p = new WangPo();
    
        p->MakeEyesWithMan();
        p->HappyWithMan();
        delete p;
    
        JiaShi *pj = new JiaShi();
        cout << "王婆为西门庆和贾氏搭桥" << endl;
        p = new WangPo(pj);
        p->MakeEyesWithMan();
        p->HappyWithMan();
        delete p;
    
        return 0;
    }

    王婆是代理方,潘金莲和贾氏氏被代理方。

  • 相关阅读:
    前端网站汇总
    更换Sublime Text主题字体
    免费收录网站搜索引擎登录口
    IE6,7,8支持css圆角
    CSS继承—深入剖析
    JavaScript正则表达式大全
    CSS伪元素选择器
    line-height用法总结
    判断腾讯QQ是否在线
    text-overflow使用文字超多div的宽度或超过在table中<td>
  • 原文地址:https://www.cnblogs.com/licb/p/9987873.html
Copyright © 2011-2022 走看看