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

    【1】什么是桥接模式?

    【2】桥接模式的代码示例

    示例代码:

     1 #include <iostream>
     2 #include <string>
     3 using namespace std;
     4 
     5 class HandsetSoft
     6 {
     7 public:
     8     virtual void run() = 0;
     9 };
    10 
    11 class HandsetGame : public HandsetSoft
    12 {
    13 public:
    14     void run()
    15     {
    16         cout << "运行手机游戏" << endl;
    17     }
    18 };
    19 
    20 class HandsetAddressList : public HandsetSoft
    21 {
    22 public:
    23     void run()
    24     {
    25         cout << "运行手机通讯录" << endl;
    26     }
    27 };
    28 
    29 class HandsetBrand
    30 {
    31 protected:
    32     HandsetSoft *soft;
    33 public:
    34     void setHandsetSoft(HandsetSoft *soft)
    35     {
    36         this->soft = soft;
    37     }
    38     virtual void run() = 0;
    39 };
    40 
    41 class HandsetBrandN : public HandsetBrand
    42 {
    43 public:
    44     void run()
    45     {
    46         soft->run();
    47     }
    48 };
    49 
    50 class HandsetBrandM : public HandsetBrand
    51 {
    52 public:
    53     void run()
    54     {
    55         soft->run();
    56     }
    57 };
    58 
    59 int main()
    60 {
    61     HandsetBrand *hb;
    62     hb = new HandsetBrandM();
    63     
    64     hb->setHandsetSoft(new HandsetGame());
    65     hb->run();
    66     hb->setHandsetSoft(new HandsetAddressList());
    67     hb->run();
    68 
    69     return 0;
    70 }
    View Code

     

    Good   Good  Study,  Day  Day  Up.

    顺序  选择  循环   总结

  • 相关阅读:
    qt 学习(三)消息基础
    qt学习(二)控件
    sqlserver学习_01
    java对文件操作--01
    js 将json字符串转换为json对象的方法解析
    实现动态代理(Java和spring)
    mysql_01_游标的使用
    java实现多文件上传01
    oracle-2_dblink的创建和使用
    sqlserver学习3---sql函数
  • 原文地址:https://www.cnblogs.com/Braveliu/p/3956668.html
Copyright © 2011-2022 走看看