I have just learned the Bridge
Pattern and its intent : Decouple an abstraction from its implementation so that the two can vary independently.
But why couldn't just an AbstractFactory
do the same thing ?
I know that an AbstractFactory
can create a particular bridge but my question concerns usage of AbstractFactory
instead Bridge
for decoupling Abstraction and Implementation.
Could you please explain me the real difference between AbstractFactory
and Bridge
Pattern?
First off the bridge pattern from what I've read is more for when both the class and what it does varies often. The class itself can be considered as the implementation and the behavior of the class as the abstraction.
The Abstract Factory on the other hand provides an interface for creating groups of related or dependent objects, without specifying their concrete classes; their implementation concerns.
So I guess to sum it up, you are comparing apples to oranges and maybe that is where the confusion is coming from. They are for solving different problems.
To me operations imply methods in java, so the operations are defined or declared by the abstraction, but are implemented in the class itself. So yes the abstraction is just declaring what the operations could do as far as behavior, but the actual implementations are done in the class. Also, the Abstract Factory is correct as well.
I guess the defining part for bridge is that it could have sets of abstractions that vary versus one abstraction.
Design Patterns uses the word abstraction to refer to a class that relies on a set of abstract operations, where several implementations of the set of abstract operations are possible.
See these links for more information: