Bridge模式( Struct Chene imp Abstraction Implementor Operations Operationlmpd) imp->OperationImp( ConcretelmplementorA ConcretelmplementorB RefinedAbstraction Operationimpo OperationImpd Participants Client, Abstraction, RefinedAbstraction, Implementor Concretelmplementor Collaborations
Bridge模式(三) • Struct • Participants – Client, Abstraction, RefinedAbstraction, Implementor, ConcreteImplementor • Collaborations
Bridge模式(四) Evaluation 抽象部分与实现部分的分离,可以在运行时刻 连接起来 二进制兼容性 提高可扩充性:抽象与实现两部分可以单独扩 充 对客户隐藏实现细节
Bridge模式(四) • Evaluation – 抽象部分与实现部分的分离,可以在运行时刻 连接起来 二进制兼容性 – 提高可扩充性:抽象与实现两部分可以单独扩 充 – 对客户隐藏实现细节
Bridge.模式(五) ° Implementation Only one Implementor Creating the right Implementor object 如何创建?根据客户环境,或者通过 factory Sharing implementors 资源管理:引用计数技术 Using multiple inheritance
Bridge模式(五) • Implementation – Only one Implementor – Creating the right Implementor object 如何创建?根据客户环境,或者通过factory – Sharing implementors • 资源管理:引用计数技术 – Using multiple inheritance
Bridge模式 Related patterns Abstract Factory可以用来创建和配置 Bridge模式 与 Adapter模式的区别 Examples handle:文件 handle、窗口 handle bndge co DrawText DevDrawText( DrawRect0 evDrawLine mp->Dev DrawL Icon window Transientwindow XWindowlmp PMWindowlmp DrawBorder0? DrawcloseBox0 9 DevDrawText0)! DevDrawLineO DevDrawLine0? DevDrawText0 Draw Texto rEcto DRawlIne( DRawsTring(
Bridge模式(六) • Related Patterns – Abstract Factory可以用来创建和配置Bridge模式 – 与Adapter模式的区别 • Examples – handle:文件handle、窗口handle
插: Handle/Body class StringRep i Handle Bod friend class String StringRep(const char *s); Points Implementation StringRepo fa nte e nt count class String i ible Counted Handle/Body String; HandIe String( const String &s) String &operator-(const String &s) Body 产ows Reference String( String( const char *S) Handle StringRep *rep
插:Handle/Body class StringRep { friend class String; StringRep(const char *s); ~StringRep(); int count; char *rep; }; class String { public: String(); String(const String &s); String &operator=(const String &s); ~String(); String(const char *s); . . . . private: StringRep *rep; }; Counted Handle/Body