Changes

Jump to: navigation, search

Bridge

887 bytes removed, 09:52, 11 June 2007
Consequences
The '''Bridge pattern''' is intended allows you to decouple an abstraction from its implementation so both can vary independently. The Bridge pattern is also know as Handle/Body.<br/><br/>
__TOC__
 
== UML Structure ==
<li>we want to hide the implementation of an abstraction completely from clients</li>
<li>we want to share an implementation among multiple objects, and this fact should be hiddent from the client</li>
<li>useful in graphic and windowing systems that need to run over multiple platforms</li>
<li>useful any time we need to vary an interface and an implementation in different ways</li>
</ul></ul>
</ul>
== Consequences ==
The Bridge pattern has the following consequence:
<ul>
<li>'''Decoupling interface and implementation'''
<ul><li> inheritance tightly couples an abstraction with an implementation at compile time. Bridge pattern can be used to avoid the binding between abstraction and implementation and to select implenetation at run time</ul>
<li>'''Improved extensibility'''
<ul><li> extend the Abstraction and Implementor hierarchies independently</ul>
<li>'''Hiding implementation detail from clients'''
<ul><li> shield clients from implentation details, like the sharing of implemntor objects and accompanying reference count merchanism</ul>
<li>'''Interface and implementation can be varied independently'''
<ul><li> maintaining two different class hierarchies for interface and implementation entitles to vary one independent of the other</ul>
<li>'''Lossely coupled client code'''
<ul><li> Abstraction separates the client code from the implementation</ul>
<li>'''Reduction in the number of sub classes'''
<li>'''Cleaner code and Reduction in executable size'''
</ul>
== Implementation ==
When applying the Bridge pattern, consider the following implementation issues:
<ul>
<ul>
<li>'''Only one Implementor'''</li>
<li>'''Creating the right Implementor object'''</li>
<li>'''Sharing implementors'''</li>
<li>'''Using multiple inheritance'''</li>
</ul>
</ul>
== Code Examples ==
====PHP Java Bridge in Java Code====The following code is found on "Oregon State University Open Source Lab" which illustrate the Bridge pattern. The following is a part of the code which allows user to vary the class loader. <br/>
Source: http://gentoo.osuosl.org/distfiles/php-java-bridge_2.0.8.tar.bz2<br/>
File: JavaBridge.java<br/>
public void updateJarLibraryPath(String path, String extensionDir) {
if(cl==null) {
bridge.logMessage("You don't have permission to call java_set_library_path() or java_require(). Please store your libraries in the lib folder within JavaBridge.war");
return;
}
====Real-world Sample code in C#====
This real-world code demonstrates the Bridge pattern in which a BusinessObject abstraction is decoupled from the implementation in DataObject. The DataObject implementations can evolve dynamically without changing any clients. <br/>Source: http://www.dofactory.com/Patterns/PatternBridge.aspx
<pre>
// Bridge pattern -- Real World example
====Sample Code in Java====
The following is an easier to follow example of the Bridge pattern:<br/>
Source: http://en.wikipedia.org/wiki/Bridge_pattern
<pre>
import java.util.*;
<li>[http://www.dofactory.com/Patterns/PatternBridge.aspx DoFactory.com - Bridge Design Pattern]</li>
<li>[http://home.earthlink.net/~huston2/dp/all_uml.html Design Class Diagrams - Bridge]</li>
<li>[Source: http://gentoo.osuosl.org/distfiles/php-java-bridge_2.0.8.tar.bz2 Oregon State University Open Source Lab - BridgeJavaBridge.java]</li>
<li>Gamma, E., Helm, R., Johnson, R., Vlissides, J. (1995). Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley. ISBN 0-201-63361-2 </li>
</ul>
1
edit

Navigation menu