Breaking down the Factory Method pattern
As part of the creational family of design patterns, the Factory Method pattern gives us the power to create objects through an interface without having to specify the exact class that’s getting instantiated. The Factory Method pattern is useful when:
- Your class can’t specify the class objects it’s required to create.
- Your class needs its subclasses to determine the objects it’s required to create.
- You need a common method or operation among all objects for instantiation.
Consider a real-world company that manufactures a variety of products as shown in Figure 4.1. A customer orders a product or products, the factory manufactures the order, and then the factory ships it back to the customer. The company’s management system doesn’t necessarily need to know the details of how each and every product is made (it doesn’t care how fidget spinners or computers are put...