Factory Method Design Pattern
Learn about the factory method design pattern.
Why do we need it?
Suppose we have an interface named Car (the interface is implemented using abstract classes in C++), and we have three classes, Ecar
, Dieselcar
, and Sportscar
, that implement the Car interface. Suppose there are different scenarios in which we would create different objects (in this case, different cars). Handling this situation is easy as we can make an algorithm that will decide which car we need to make.
Get hands-on with 1400+ tech skills courses.