zoukankan      html  css  js  c++  java
  • 桥接模式

    1】什么是桥接模式?
    
    【2】桥接模式的代码示例
    
    示例代码:
    #include <iostream>
    #include <string>
    using namespace std;
    
    class HandsetSoft
    {
    public:
        virtual void run() = 0;
    };
    
    class HandsetGame : public HandsetSoft
    {
    public:
        void run()
        {
            cout << "运行手机游戏" << endl;
        }
    };
    
    class HandsetAddressList : public HandsetSoft
    {
    public:
        void run()
        {
            cout << "运行手机通讯录" << endl;
        }
    };
    
    class HandsetBrand
    {
    protected:
        HandsetSoft *soft;
    public:
        void setHandsetSoft(HandsetSoft *soft)
        {
            this->soft = soft;
        }
        virtual void run() = 0;
    };
    
    class HandsetBrandN : public HandsetBrand
    {
    public:
        void run()
        {
            soft->run();
        }
    };
    
    class HandsetBrandM : public HandsetBrand
    {
    public:
        void run()
        {
            soft->run();
        }
    };
    
    int main()
    {
        HandsetBrand *hb;
        hb = new HandsetBrandM();
        
        hb->setHandsetSoft(new HandsetGame());
        hb->run();
        hb->setHandsetSoft(new HandsetAddressList());
        hb->run();
    
        return 0;
    }
  • 相关阅读:
    BZOJ1040: [ZJOI2008]骑士
    Codeforces 849D.Rooter's Song
    POJ4852 Ants
    NOIP模拟赛 17.10.10
    Codeforces 851D Arpa and a list of numbers
    BZOJ2529: [Poi2011]Sticks
    BZOJ1826: [JSOI2010]缓存交换
    POJ3579 Median
    codevs1214 线段覆盖
    POJ2230 Watchcow
  • 原文地址:https://www.cnblogs.com/leijiangtao/p/4534558.html
Copyright © 2011-2022 走看看