Difference between Strategy and Factory design patterns

A Strategy pattern is an operational pattern. Strategy pattern allows you to polymorphically change behavior of a class. Strategy pattern is to avoid conditionals switching in favor of polymorphism.
So, Strategy pattern = polymorphism.

A Factory pattern is a creational pattern. Factory pattern allows you to encapsulate object creation.
Factory pattern = encapsulation.

A difference between Simple Factory and Abstract Factory. Simple Factory – you only have one class which acts as a factory for object creation. Abstract Factory – you connect to an interface and then call the different factories that implement this interface which are supposed to have different implementations of the same method based on some criteria.

Abstract Factory looks like a strategy pattern, but it differs from it semantically because it is used for OBJECT CREATION rather than operations. So, basically you have object creation using different strategies.

Leave a Reply