1 / 15

The Bridge Pattern

The Bridge Pattern. Guang Hu February 2002. Overview. Motivation Participants Structure Applicability Benefits Drawbacks Related Pattern. Entry. oracleDBEntry. FilesysEntry. Motivation. Entry. Appointment. Task. OracleDBApp. FilesysApp. OracleDBTask. FilesysTask. Motivation.

lidia
Download Presentation

The Bridge Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Bridge Pattern Guang Hu February 2002

  2. Overview • Motivation • Participants • Structure • Applicability • Benefits • Drawbacks • Related Pattern

  3. Entry oracleDBEntry FilesysEntry Motivation

  4. Entry Appointment Task OracleDBApp. FilesysApp. OracleDBTask FilesysTask Motivation

  5. Task getPriority() setPriority() getText() setText() Destroy() Appointment getAlarm() setAlarm() getText() setText() Destroy() PersistentImp. initialize() store() load() Destroy() Entry getText() setText() Destroy() impl Bridge OraclePImp initialize() store() load() destroy() AccessPImp initialize() store() load() destroy() Motivation

  6. Participants • Abstraction (Entry): - define the abstraction’s interface - maintains a reference to an object of type Implementor • Refined Abstraction (Task): - extends the interface defined by Abstraction

  7. Participants (continue) • Implementor (persistentImp): - defines an interface for implementation classes. Typically, this Implementor’s interface provides only primitive menthod • ConcreteImplementor (oraclePImp, AccessPImp): - implements the Implementor’s interface

  8. Client Implementer Abstraction impl OperationImp() ConcreteImplementerB RefinedAbstraction ConcreteImplementerA Structure

  9. Applicability • Want toavoid a permanent binding between an abstraction and implementation. • When abstractions and implementations should be extensible through subclassing. • When implementation changes should not impact clients.

  10. Applicability (continue) • When the implementation should be completely hidden from the client. (C++) • When you have a proliferation of classes. • When, unknown to the client, implementations are shared among objects.

  11. Benefits • Avoid permanent binding between an abstraction and its implementation • Avoid nested generalizations • Ease adding new implementations • Reduce code repetition • Allow runtime switching of behaviour

  12. Drawbacks • Double indirection - “entry”operation are implemented by subclasses ofPersistentImp class. Entryclass must delegate the message to a PersistentImp subclass which implements the appropriate method. This will have a slight impact on performance.

  13. Consequences • decoupling interface & implementation - implementation of abstraction - can be configured at run-time - eliminate compile time dependencies on implementation - encourages layering • improved extensibility - Abstraction & Implementer - can be extended independently • hiding implementation details from clients

  14. Related Pattern • Abstract Factory- The Abstract Factory pattern can be used by the Bridge pattern to decide which implementation class to instantiate for an abstraction object. • Adapter

  15. Thank you

More Related