0% found this document useful (0 votes)
2 views

3-design-patterns-java-structural-m3-slides

The Bridge Pattern decouples abstraction from implementation, allowing for changes in abstraction without affecting the client. It emphasizes the use of interfaces and abstract classes, promoting composition over inheritance while preparing for changes on both sides. Although it offers flexibility and is designed for uncertainty, it can increase complexity and may be conceptually challenging to implement.

Uploaded by

podam91581
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

3-design-patterns-java-structural-m3-slides

The Bridge Pattern decouples abstraction from implementation, allowing for changes in abstraction without affecting the client. It emphasizes the use of interfaces and abstract classes, promoting composition over inheritance while preparing for changes on both sides. Although it offers flexibility and is designed for uncertainty, it can increase complexity and may be conceptually challenging to implement.

Uploaded by

podam91581
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Bridge Pattern

Bryan Hansen
twitter: bh5k | http://www.linkedin.com/in/hansenbryan
Concepts
▪ Decouple Abstraction and implementation
▪ Encapsulation, Composition, Inheritance
▪ Changes in Abstraction won’t affect client
▪ Details won’t be right
▪ Examples:
▪ Driver
▪ JDBC
Design

Interfaces and Abstract classes


Composition over Inheritance
More than Composition
Expect change from both sides
Abstraction, Implementor, Refined
Abstraction, Concrete Implementor
UML
Everyday Example - JDBC

DriverManager.registerDriver(new  org.apache.derby.jdbc.EmbeddedDriver());    

String  dbUrl  =  "jdbc:derby:memory:codejava/webdb;create=true";  

Connection  conn  =  DriverManager.getConnection(dbUrl);  

Statement  sta  =  conn.createStatement();


Exercise Adapter

Color and Shape


Color and Shape Bridge
Create Bridge
Another Bridge
Pitfalls
▪ Increases complexity
▪ Conceptually difficult to plan
▪ More than just OO
▪ What goes where
Contrast

Bridge Adapter
▪ Designed upfront ▪ Works after code is designed
▪ Abstraction and implementation ▪ Legacy
vary ▪ Retrofitted
▪ Built in advance ▪ Provides different interface
▪ Complex
Bridge Summary

• Design for uncertainty


• Can be complex
• Provides flexibility
• More than composition

You might also like