- Intent: decoupling parts of an object to a sublcass in order to avoid combinatorial explosion
- Decouples abstraction from its implementation so that the two can vary indepedently
- You have a
Abstraction
that takes in any Implementor
, and you have an Implementor
that can work with any (register in the BaseClass) Abstraction
- Components
- Abstraction (the what) ⇒ client-facing interface
- Contains reference to
Implemntor
which executes the actual work
- High-level
- Extends
Abstraction
for the customized version of a given subject
- Implementation (the how) ⇒ functionality to be given for the Abstraction (contains several ones)
- Low-level
- You can have several ones
- Bridge ⇒ via object composition
- Use-case
- Decoupling the what from the how
- When you have MxN problem (where M is subject/abstraction and N is functionality/implementor)
- Notes
- Difference to Factory is that factory is concerned of the proper object creation based on factory instance, whereas bridge defines a different relationship in the structure of the object (not in its creation).
Factory
decouples client request for an object from how its instantiated
Brige
decouples abstraction from implementation
- Code
QUESTIONS
- What is object composition?
- In comparision with inheritance (is-a relationship), object composition (has-a relationship) aims to create complex objects by being built out of small subobjects (that are specialized)
- What is a primitive?
- Fundamental data type used to build more complex interfaces
- I dont understand hierahchy of class nor refined abstraction