Using UML Patterns and Java ObjectOriented Software Engineering

Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Design Patterns Bridge

A Pattern Taxonomy Pattern Structural Pattern Behavioral Pattern Creational Pattern Composite Decorator Adapter Bridge Façade Proxy Iterator Command Observer Template Strategy Singleton Abstract Factory Builder Factory Prototype Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2

Bridge Pattern ¨ Use a bridge to “decouple an abstraction from its implementation so that the two can vary independently”. (From [Gamma et al 1995]) ¨ Also know as a Handle/Body pattern. ¨ Allows different implementations of an interface to be decided upon dynamically. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3

Using a Bridge ¨ ¨ ¨ The bridge pattern is used to provide multiple implementations under the same interface. Examples: Interface to a component that is incomplete, not yet known or unavailable during testing JAMES Project: if seat data is required to be read, but the seat is not yet implemented, known, or only available by a simulation, provide a bridge: VIP Seat (in Vehicle Subsystem) Get. Position() Stub Code Bernd Bruegge & Allen H. Dutoit imp Seat. Implementation AIMSeat Object-Oriented Software Engineering: Using UML, Patterns, and Java SARTSeat 4

Seat Implementation public interface Seat. Implementation { public int Get. Position(); public void Set. Position(int new. Position); } public class Stubcode implements Seat. Implementation { public int Get. Position() { // stub code for Get. Position }. . . } public class Aim. Seat implements Seat. Implementation { public int Get. Position() { // actual call to the AIM simulation system }. . . } public class SARTSeat implements Seat. Implementation { public int Get. Position() { // actual call to the SART seat simulator }. . . } Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5

Bridge Pattern Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6

Adapter vs Bridge ¨ Similarities: w Both are used to hide the details of the underlying implementation. ¨ Difference: w The adapter pattern is geared towards making unrelated components work together t Applied to systems after they’re designed (reengineering, interface engineering). w A bridge, on the other hand, is used up-front in a design to let abstractions and implementations vary independently. t t Green field engineering of an “extensible system” New “beasts” can be added to the “object zoo”, even if these are not known at analysis or system design time. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
- Slides: 7