Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bridge The decoupling of abstraction and implementation.

Similar presentations


Presentation on theme: "Bridge The decoupling of abstraction and implementation."— Presentation transcript:

1 Bridge The decoupling of abstraction and implementation

2 Ideas GoF Intentions –Decouple an abstraction from it implementation so that the two can vary independently Metsker –Focuses on the implementation of an abstraction

3 Other Structural Patterns Adapter Composite Decorator Façade Flyweight Proxy

4 Uses You want to avoid a permanent binding between an abstraction and it's implementation. This might be the case, for example, when the implementation must be selected or switched at run-time. Both the abstractions and their implementations should be extensible by sub-classing. In this case, the Bridge pattern lets you combine the different abstractions and implementations and extend them independently. Changes in the implementation of an abstraction should have no impact on clients; that is, their code should not have been recompiled.

5 Real Uses What are some common uses of the Bridge pattern? –Drivers Applications System drivers –Window Interfaces X Window System Microsoft Windows –Application Programming Interfaces MFC JDBC

6 UML Diagram

7 Drivers JDBC is an application programming interface for executing SQL statements The drivers for JDBC and the applications that use JDBC are completely independent of each other –The same application can use an Oracle driver just as easily as a MySQL or Postgres driver

8 Challenge 6.1 Fill in the missing type names and the missing message name following illustration Class.forName(driverName); Connection c = DriverManager.getConnection(url, user, passwd); Statement s = c.createStatement(); ResultSet r = s.executeQuery(“select name, apogee from fireworks”); while(r.next()) { String name = r.getString(“name”); int apogee = r.getInt(“apogee”); System.out.println(name + “, “ + apogee); }

9 Challenge 6.1 Continued Fill in the missing type names and the missing message name following illustration

10 Abstract Class Refactoring Sometimes it is advantageous to refactor an abstract class to a Bridge pattern to gain more flexibility in the abstraction For instance, to separate the real-world implementation and a tester implementation

11 MachineController Refactoring Subclasses of MachineController exist for various types of machines and for various types of controllers Steps to refactor: –Move the abstract operations in the superclass into an interface –Define implementation classes that provide different implementations of the interface –Redefine the remaining operations in the abstract class as operations of the new interface

12 Challenge 6.3 Fill in the missing labels for MachineController interface

13 Summary Decoupling interface and implementation Improved extensibility Hiding implementation details from clients Other Patterns and Bridge –Abstract Factor can create and configure a particular Bridge –The Adapter and Bridge patterns are similar, but usually the Adapter pattern is used after the classes are created where as the Bridge pattern is used from in the ground-up design


Download ppt "Bridge The decoupling of abstraction and implementation."

Similar presentations


Ads by Google