设计模式读书笔记:Bridge(桥接)
来源:互联网 发布:万方数据库高级检索 编辑:程序博客网 时间:2024/06/06 01:17
意图:
将抽象部分与它的实现部分分离,使它们都可以独立地变化。
结构图:来自 《23种设计模式 - 郗晓勇》
实现:https://github.com/panshiqu/patterns/tree/master/Bridge
Implementor
namespace NS_BRIDGE {class Implementor {public:Implementor() {}virtual ~Implementor() {}virtual void operationImp(void) = 0;};} /* namespace NS_BRIDGE */ConcreteImplementorA
#include "Implementor.h"#include <iostream>namespace NS_BRIDGE {class ConcreteImplementorA : public Implementor{public:ConcreteImplementorA() {}virtual ~ConcreteImplementorA() {}virtual void operationImp(void){std::cout << "ConcreteImplementorA" << std::endl;}};} /* namespace NS_BRIDGE */ConcreteImplementorB
#include "Implementor.h"#include <iostream>namespace NS_BRIDGE {class ConcreteImplementorB : public Implementor{public:ConcreteImplementorB() {}virtual ~ConcreteImplementorB() {}virtual void operationImp(void){std::cout << "ConcreteImplementorB" << std::endl;}};} /* namespace NS_BRIDGE */Abstraction
#include "Implementor.h"namespace NS_BRIDGE {class Abstraction {public:Abstraction(Implementor *imp) : _imp(imp) {}virtual ~Abstraction() {}virtual void operation(void){_imp->operationImp();}private:Implementor *_imp;};} /* namespace NS_BRIDGE */main
#include "Bridge/Abstraction.h"#include "Bridge/ConcreteImplementorA.h"#include "Bridge/ConcreteImplementorB.h"using namespace NS_BRIDGE;int main(void){// 可以使用Abstract Factory创建实现// 如此以来这段代码将不依赖或需要知道任何实现ConcreteImplementorA ia;Abstraction abs(&ia);abs.operation();}附加:
0 0
- 设计模式读书笔记:Bridge(桥接)
- 设计模式读书笔记(四) Bridge(桥梁)模式
- 设计模式--桥接(Bridge)模式
- 设计模式:Bridge(桥接)模式
- Bridge(桥接)设计模式
- JAVA设计模式:桥接(Bridge)
- 设计模式读书笔记之桥接模式(bridge pattern)
- 设计模式读书笔记之桥接模式(bridge pattern)
- 《设计模式解析》读书笔记之Bridge Pattern(桥接模式)
- 设计模式之Bridge(桥接)
- 【初学设计模式】Bridge (桥接)
- 设计模式学习-Bridge(桥接)
- (7)设计模式:bridge
- 设计模式(六)bridge
- 设计模式(7)——Bridge模式(桥接)
- 23种设计模式09---桥接(Bridge)模式
- 设计模式(6)-桥接(Bridge)模式
- java设计模式学习—桥接(Bridge)模式
- PHP异常处理
- 【thinkphp】【mac环境配置】mac上使用mamp配置环境thinkphp访问出现目录无权限的解决办法
- Servlet——Session会话mini项目
- 控件:可见、隐身、走开
- convertview与viewholder
- 设计模式读书笔记:Bridge(桥接)
- c# 窗口关闭提示
- Linux下 MySQL Show命令的使用
- 重新开始BAE
- 十年WEB技术发展历程
- Nodejs中when库的实例介绍
- 图像微分(1、2阶导数和拉普拉斯算子)
- Android5.0网络之多网络共存与应用
- codeforces 448 A. Rewards