设计模式 桥接模式(Bridge Pattern)
来源:互联网 发布:mac版wifi破解软件 编辑:程序博客网 时间:2024/06/10 08:31
Bridge
- 目的
- 结构
- 应用
- 结论
- 源码
目的
- 从实现中分离出抽象,因此这两个可以独立改变。.
结构
- Abstraction : 定义一个抽象接口.
- RefinedAbstraction : 扩展抽象定义的接口.
- Implementor : 定义一个实现接口类.
- ConcreteImplementor : 实现实现接口类定义的接口.
应用
- 你想避免抽象及其实现之间的永久绑定,这是一个例子,当在运行时实现必须选择或交换。
- 抽象和其实现应该是可扩展的子类,在这种情况下,桥接模式可以结合不同的抽象和实现和独立地扩展他们。
- 实现一个抽象的变化应该对客户端没有影响;也就是客户端的代码不需要重新编译。
- 你需要完全从客户端隐藏抽象的实现方法。在c++中代表只是显示接口的类。
- 你想在多个对象中共享实现,这就需要从客户端中隐藏。
结论
- 分离接口和实现。
- 提高可扩展性。
- 从客户端中隐藏实现细节。
源码
class Implementor {
public:
void OperationImp();};
class ConcreteImplementor : public Implementor {
};
#include "Implementor.h"
class Abstraction {
public:
void Operation();
Implementor *imp;
};
#include "Abstraction.h"
class RefinedAbstraction : public Abstraction {
};
0 0
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式--桥接模式(bridge pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-桥接模式(Bridge Pattern)
- 设计模式 桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式【桥接模式Bridge Pattern】
- JavaScript基础——函数表达式
- 如何在win cmd中进行电脑重启
- Latex排版全解
- https 例子
- 鼠标右击菜单
- 设计模式 桥接模式(Bridge Pattern)
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- cocos2dx-v3.0命令行创建工程
- Mongodb学习笔记速记(三)
- Ubuntu linux下运行xv6
- View机制深入学习(四)View的事件分发机制
- Android自定义捕获Application全局异常
- Yarn的JVM重用功能——uber
- Kernel.shmall和kernel.shmmax