Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AbstractFactory Versus Bridge Pattern

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?

like image 880
Mik378 Avatar asked Oct 09 '11 01:10

Mik378


People also ask

What is the difference between factory pattern and Abstract Factory pattern?

The main difference between a “factory method” and an “abstract factory” is that the factory method is a single method, and an abstract factory is an object. The factory method is just a method, it can be overridden in a subclass, whereas the abstract factory is an object that has multiple factory methods on it.

When should we use Abstract Factory pattern?

When to Use Abstract Factory Pattern: The client is independent of how we create and compose the objects in the system. The system consists of multiple families of objects, and these families are designed to be used together. We need a run-time value to construct a particular dependency.

What is the difference between Bridge pattern and adapter pattern?

Adapter pattern is used after the application components are designed so that we can use them without modifying the source code. This is in contrast to the Bridge pattern, which is used before the components are designed.


1 Answers

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:

Using Abstractions and the Bridge Pattern in Java

Wikipedia: Bridge_Pattern

Bridge Pattern in Java

The Bridge Pattern Design Pattern

like image 98
James Drinkard Avatar answered Sep 23 '22 00:09

James Drinkard