Exploring creational design patterns
Creational design patterns are various methods to add abstraction in the process of object creation. In this section, we will be looking at three such design patterns, namely the factory method, prototype pattern, and singleton pattern.
Understanding the factory method
The factory design pattern is a method of abstraction where a factory class is created to create an object for the class from the factory class instead of directly instantiating the object. To explain this further and to implement this design pattern, our code needs the following elements:
- Abstract class: The abstract class with the abstract methods for functionalities to be defined in the subclasses.
- Abstraction subclasses: The subclasses are inherited from the abstract class and overwrite the abstract methods.
- Factory class: The class to create objects for the abstraction subclasses.
- End user method: The class or method to test or call the factory method...