Chaper 1 Questions by wuzhengqin

VIEWS: 11 PAGES: 5

									                                     Bridge Design Pattern
http://en.wikipedia.org/wiki/Bridge_pattern

http://www.cs.uofs.edu/~bi/2003f-html/se516/bridge.htm

http://www.dofactory.com/Patterns/PatternBridge.aspx

http://sourcemaking.com/design_patterns/bridge

http://www.cs.clemson.edu/~malloy/courses/patterns/bridge.html

Cascading Bridge:
http://www.hillside.net/plop/plop98/final_submissions/P41.pdf

http://www.codeproject.com/KB/scripting/jbridge.aspx?fid=343307&df=90&mpp=25&sort=Position&tid=
       1682879

JavaScript VectorGraphics
http://www.codeproject.com/KB/scripting/jbridge.aspx

Drivers
http://www.informit.com/articles/article.aspx?p=29302

http://www.codeproject.com/KB/architecture/bridge.aspx

http://www.oodesign.com/bridge-pattern-object-persistence-api-example-java-sourcecode.html

http://today.java.net/pub/a/today/2004/10/29/patterns.html
                                                      Bridge Pattern

Decouple an abstraction from its implementation so that the two can vary independently.




The Abstraction defines the interface that the client uses for interaction with this abstraction. That is, the client makes requests
directly to the Abstraction object, as that is the only interface known to the client. The Abstraction object also maintains a
reference to an Implementor object. The collaboration between the objects in this pattern is such that the clients requests are
forwarded by the Abstraction to the Implementor through this reference. A RefinedAbstraction, then, is simply any and all
extensions to the Abstraction class. The Implementor defines the interface for any and all implementations of the Abstraction.
There is no requirement that the Abstraction interface and the Implementor interface have a 1 to 1 correspondence. This is one
of the main reasons for the additional flexibility gained from this pattern. For example, the Abstraction could be a vehicle with a
draw() method, and the Implementor interface may have the methods drawWheel() and drawBody(). draw(), then, could make
one call to drawBody() and four calls to drawWheel(). As Gamma states, "Typically the Implementor interface provides only
primitive operations, and Abstraction defines higher-level operations based on these primitives." (Gamma, 1995, pg 154) As
may be guessed, the ConcreteImplementor simply implements the interface defined by the Implementor class. That is, it
defines a concrete implementation of the Abstraction.
Example:




Use the Bridge pattern when:

      You want run-time binding of the implementation,
      You have a proliferation of classes resulting from a coupled interface and numerous
       implementations,
      You want to share an implementation among multiple objects,
      You need to map orthogonal class hierarchies.

Similar to Adapter pattern.

Similar to Strategy pattern.

Similar in structure to Abstract Factory

Similar in structure to State pattern.
Known Uses

This section presents known uses of Bridge Pattern. Some of the known uses presented in this section are taken from the GoF
book on Design Patterns.

MFC and Bridge Pattern

In MFC, the process of storing/retrieving an object to/from a persistence mechanism (like a file) is called Serialization. MFC uses
the Bridge Pattern to implement Serialization. CArchive and CFile classes implement object Serialization. CArchive class provides
the interface for writing/reading an object to/from a persistence mechanism whereas the CFile and its sub classes provides
implementation for different persistence mechanisms such as memory, disk file, sockets etc.

A CArchive object is configured with an object of class CFile (or a derived class) during its construction, from which it obtains the
necessary information for serialization, including the filename and type of the requested operation (a read or write). Client
performing the Serialization operation can use CArchive object without regarding the persistence mechanism implemented by
CFile classes.

Java and Bridge Pattern

Java uses the Bridge Pattern to separate Components and Component Peers. Java applications can run on different platforms,
so the client code should be able to create a Component without committing to a concrete implementation. The Components
and Component Peers are represented as two different class/interface hierarchies. Every AWT Component sub class has a
corresponding Component Peer sub interface with which it can communicate. Platform specific classes implement these
Component Peer interfaces.

								
To top