Member-only story
The Factory Method Design Pattern
A creational design pattern that all devs should be using!
The purpose of design patterns is to outline solutions to various common software design problems. Becoming popular by the Gang of Four, design patterns provide a theoretical approach on how to solve common challenges that software engineers meet on a daily basis. They do not constitute specific code implementations, therefore they can be adopted and implemented appropriately in many programming languages. Design patterns are separated in three general categories; creational, structural and behavioral. In this post I’m presenting the factory method, a creational design pattern.
Suppose that you run a tire shop and you have a standard procedure to install tires on car wheels. One day you realize that there is high demand from customers to install tires on trucks as well. And after a while you are called to do the same on motorcycles. In order to cover these new demands, you add two new procedures so you can adapt and serve the new vehicle types respectively. And right when you have put all new stuff in motion, there it comes the need to introduce a fourth procedure in order to work with bicycles as well.
Let’s say that the tire installation procedure on each vehicle type can be represented programmatically by a class. The client code, the…