桥接模式

【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.

顺序  选择  循环   总结

posted @   kaizenly  阅读(336)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
历史上的今天:
2013-09-04 资源共享型智能指针实现方式
打赏

喜欢请打赏

扫描二维码打赏

微信打赏

点击右上角即可分享
微信分享提示