Java Reference
In-Depth Information
Implementation - The Implementation interface represents the underlying functionality used by the
Abstraction instances.
ConcreteImplementation - ConcreteImplementation implements the Implementation interface. It provides
the behavior and structure for Implementation classes.
Benefits and Drawbacks
The Bridge offers the potential to share underlying implementation objects among multiple abstraction objects. It
provides greater flexibility when changing implementations, and the changes can occur without any action
required on the part of the client.
When designing an application that uses the Bridge pattern, it is important to properly define which
responsibilities belong to the functional abstraction and which belong to the internal implementation class.
Likewise, you must carefully consider what represents the true base model for your implementation of the Bridge
pattern. A common problem you might experience when using the Bridge stems from developing the pattern
implementation around one or two possible variations. The danger is that future development of the pattern will
reveal that some of the assumed elements of core behavior actually represented specific variations based on the
abstraction and/or implementation.
Like many of the distributed object patterns, you might also need to consider what the concept of equality really
means for the Bridge. Does the abstraction or the implementation, or both, represent the important object for
comparison?
Pattern Variants
Pattern variants include the following:
Automatic Bridges - Some Bridge pattern implementations are made to vary their implementation without any
action by the end user, relying instead on information provided from the application or operating platform to
customize themselves.
Shared implementations - Some implementation classes, especially stateless ones (classes that do not maintain
an internal state), can be shared among multiple application objects. Depending on how widely they can be shared,
such classes can potentially be implemented as an interface.
Single implementation - Sometimes there is only a single implementation class, which services multiple
abstraction classes. If there is only a single implementation, it is probably not necessary to define a base class for
the implementation part of a Bridge.
Related Patterns
Related patterns include the following:
Adapter (page 142) - The Bridge and the Adapter pattern are very similar in structure but differ in their intent.
The Bridge pattern separates the abstraction and the implementation to allow both to change independently, and is
an upfront design choice. The Adapter pattern enables use of an object whose interface would otherwise be
incompatible.
Singleton (page 34) - As mentioned in the variants section the Singleton pattern can be used when
“ implementation ” classes can be shared.
Flyweight (page 183) - When the tree structure becomes large, applying the Flyweight pattern can help reduce
the number of objects managed by the tree.
Example
Note:
For a full working example of this code example, with additional supporting classes and/or a RunPattern class,
see “ Bridge ” on page 448 of the “ Full Code Examples ” appendix.
Search WWH ::




Custom Search