Since this is well explained in our study book (with good diagrams), I'll only be putting up an outline here.
Bridge Pattern - aka Handle/Body
Decouple Abstraction from Implementation
Common tendency - handle special cases with inheritance.
Example problem space using inheritance - see UML diagrams pg 127, 128
What if we add another drawing program.
Solution: Take the variations and encapsulate them by putting into different classes.
There are two main OO concepts employed here:
1. Find what varies and encapsulate it
2. Favor object composition over inheritance
Seen in Java's java.awt package:
Component is the abstract class that represents the abstraction
Inherited from Component are Button, Text
Field, List, etc.
java.awt.peer contains interfaces for the platform specific implementations -
ComponentPeer,
ButtonPeer,
ListPeer, etc.
java.awt.Toolkit acts as the
AbstractFactory (next meeting) that is used by the sublasses of
Component to create their implementations. Thus, the platform supplies the concrete factory class.
Consequences(from GOF)
1. Decouples interface and implementation
2. Improves extensibility
3. Hides implementation details from clients
Implementation issues (from GOF)
1. Only one implementator (degenerate case)
2. Creating the best Implementor object
3. Sharing Implementors
Patterns often used with:
Adapter
AbstractFactory
If time permits: Another (interactive) example.