Quantcast
Channel: What are the differences between Abstract Factory and Factory design patterns? - Stack Overflow
Viewing all articles
Browse latest Browse all 22

Answer by Islam Alshnawey for What are the differences between Abstract Factory and Factory design patterns?

$
0
0

A) Factory Method pattern

The Factory Method is a creational design pattern that provides an interface for creating objects but allows subclasses to alter the type of an object that will be created.

If you have a creation method in base class and subclasses that extend it, you might be looking at the factory method.

B)Abstract Factory pattern

The Abstract Factory is a creational design pattern that allows producing families of related or dependent objects without specifying their concrete classes.

What are the "families of objects"? For instance, take this set of classes: Transport + Engine + Controls. There are might be several variants of these:

1- Car + CombustionEngine + SteeringWheel

2- Plane + JetEngine + Yoke

If your program doesn’t operate with product families, then you don’t need an abstract factory.

And again, a lot of people mix-up the abstract factory pattern with a simple factory class declared as abstract. Don’t do that!

REF: https://refactoring.guru/design-patterns/factory-comparison


Viewing all articles
Browse latest Browse all 22

Trending Articles