Bridge Pattern Flashcards
What is the Bridge Pattern?
A structural design pattern that decouples an abstraction from its implementation, allowing both to vary independently.
When would you use the Bridge Pattern?
When you want to avoid a permanent binding between an abstraction and its implementation and both can change independently.
What are the components of the Bridge Pattern?
- Abstraction
- RefinedAbstraction
- Implementation
- ConcreteImplementation
What does the Abstraction component do in the Bridge Pattern?
Defines the high-level interface that the client uses.
What is the purpose of the RefinedAbstraction in the Bridge Pattern?
Extends the abstraction to add more specific behavior.
What is the role of the Implementation in the Bridge Pattern?
Defines the interface for implementation classes.
What does ConcreteImplementation do?
Implements the implementation interface for specific platforms or variants.
What is a key advantage of the Bridge Pattern?
Separation of Concerns: Abstraction and implementation can evolve independently.
How does the Bridge Pattern promote extensibility?
New abstractions and implementations can be added without modifying existing code.
What is a disadvantage of the Bridge Pattern?
Increased Complexity: Introduces additional classes and interfaces, which can make the code harder to understand.
How does the Bridge Pattern relate to the Adapter Pattern?
The Bridge Pattern decouples abstraction from implementation, while the Adapter Pattern makes incompatible interfaces work together.
What is the focus of the Strategy Pattern compared to the Bridge Pattern?
Strategy Pattern focuses on changing behavior dynamically, while Bridge Pattern focuses on separating abstraction and implementation.
What is the purpose of creating concrete implementations in the Bridge Pattern?
To implement the implementation interface for each platform or variant.
Fill in the blank: The Bridge Pattern helps avoid _______.
class explosion.
True or False: The Bridge Pattern is used to adapt existing classes to work together.
False.
What is a real-world analogy for the Bridge Pattern?
A remote control (abstraction) and a TV (implementation) that can work together without needing to change the remote when the TV changes.
What happens without the Bridge Pattern when you have multiple dimensions?
You would need a separate subclass for every combination, leading to class explosion.
What does the client code do in the Bridge Pattern?
Associates the abstraction with a concrete implementation and uses the abstraction.
What is the UML diagram structure for the Bridge Pattern?