博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
桥接模式
阅读量:7027 次
发布时间:2019-06-28

本文共 1195 字,大约阅读时间需要 3 分钟。

【1】什么是桥接模式?

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

示例代码:

1 #include 
2 #include
3 using namespace std; 4 5 class HandsetSoft 6 { 7 public: 8 virtual void run() = 0; 9 };10 11 class HandsetGame : public HandsetSoft12 {13 public:14 void run()15 {16 cout << "运行手机游戏" << endl;17 }18 };19 20 class HandsetAddressList : public HandsetSoft21 {22 public:23 void run()24 {25 cout << "运行手机通讯录" << endl;26 }27 };28 29 class HandsetBrand30 {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 HandsetBrand42 {43 public:44 void run()45 {46 soft->run();47 }48 };49 50 class HandsetBrandM : public HandsetBrand51 {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.

顺序  选择  循环   总结

转载地址:http://ndrxl.baihongyu.com/

你可能感兴趣的文章
Redis源码分析系列26:对redis的一点小感触
查看>>
phpstudy 性能调优
查看>>
JDK源码解读(1)ArrayList和LinkedList
查看>>
第22讲: Scala中的闭包实战详解
查看>>
linux信号解释(1)
查看>>
串口DTU设备常见问题处理
查看>>
28.umask值
查看>>
文件操作工具类
查看>>
nginx教程从入门到精通(ttlsa出品)
查看>>
squid日志之access.log格式+内容
查看>>
我的友情链接
查看>>
LVS NAT 模式突然很卡ip_conntrack
查看>>
重拾CCNA,学习笔记持续更新ing......(7)
查看>>
FreeBSD下的开机自启动
查看>>
我的友情链接
查看>>
Linux命令行快捷键
查看>>
python 的实用技巧
查看>>
创建RHCS集群环境
查看>>
电子商务未来的趋势,难道我真的错了?
查看>>
工厂方法模式
查看>>