The Bridge - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

The Bridge

Description:

see: http://java.sun.com/blueprints/patterns/j2ee_patterns/data_access_object/in dex.html ... depending on whether an Cloudscape, Oracle, or Sybase database is used. ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 7
Provided by: quddus3
Category:
Tags: bridge

less

Transcript and Presenter's Notes

Title: The Bridge


1
The Bridge
  • A Structural Design Pattern
  • Presented by Quddus Chong
  • CS590L Winter 2002

2
The Problem
  • Many implementations for one abstraction.
  • High coupling - lacks flexibility.
  • Inheritance property could be misused to
    specialize subclasses for different
    implementations - This leads to code duplication,
    platform dependence, and less manageable
    hierarchies.

Window
Window
Swing_ Window
MFC_ Window
IconWindow
Swing_ Window
MFC_ Window
Swing_ IconWindow
MFC_ IconWindow
3
The Solution
  • Separate the abstraction class hierarchy from the
    implementation class hierarchy and use delegation
    as a bridge between the two.
  • Abstraction defines the abstractions interface
  • RefinedAbstraction extends the interface
    defined by Abstraction
  • Implementor defines the interface for
    implementation classes can be different from
    Abstraction interface. Typically, Implementor
    provides only primitive operations, and
    Abstraction defines higher-level operations based
    on these primitives.
  • ConcreteImplementor implements the Implementor
    interface and defines its concrete implementation.

4
The Solution (contd.)
  • Consequences include
  • Decoupling interface and implementation
  • Improved extensibility
  • Hiding implementation details from clients

bridge
Window
WindowImp
DrawText() DrawRect()
DevDrawText() DevDrawLine()
imp-gtDevDrawLine() imp-gtDevDrawLine() imp-gtDevDra
wLine() imp-gtDevDrawLine()
IconWindow
TransientWindow
Swing_ WindowImp
MFC_WindowImp
DrawBorder()
DrawCloseBox()
DevDrawText() DevDrawLine()
DevDrawText() DevDrawLine()
DrawRect() DrawText()
DrawRect()
Swing_ DrawLine()
Swing_ DrawString()
5
Applicability and Implementation
  • Use the bridge when
  • You want to avoid a permanent binding between an
    abstraction and its implementation.
  • Both the abstractions and their implementations
    should be extensible by subclassing.
  • Changes in the implementation of an abstraction
    should have no impact on clients (i.e. code
    should not have to be recompiled).
  • You want to share an implementation among
    multiple objects, and want to hide this from the
    client.
  • Some implementation issues
  • Only one Implementor an abstract Implementor is
    not necessary when there is only one
    implemetation.
  • Creating the right Implementor object - how to
    decide which Implementor to instantiate?
  • Can be instantiated in the constructor for
    Abstraction choose a default implementation and
    change it later according to usage.
  • A better approach Delegate the decision making
    to a Abstract Factory object.

6
Example J2EE Data Access Object (DAO)
  • see http//java.sun.com/blueprints/patterns/j2ee
    _patterns/data_access_object/index.html
  • In the example, Java PetStore application
    OrderEJB component uses an associated OrderDAO
    class to access a specific database
  • At deployment time, the application
    administrator configures the implementation of
    OrderDAO to be one of OrderDAOCS, OrderDAOOracle,
    or OrderDAOSybase, depending on whether an
    Cloudscape, Oracle, or Sybase database is used.
Write a Comment
User Comments (0)
About PowerShow.com