🎨 Design Patterns (Gang of Four)
Beginner
What is the Factory Method design pattern?
Answer
The Factory Method pattern defines an interface for creating an object but lets subclasses decide which class to instantiate. The creator class declares an abstract factory method, and each concrete subclass overrides it to produce a product appropriate for itself. For example, a LogisticsApp might declare a createTransport() factory method, with RoadLogistics returning a Truck and SeaLogistics returning a Ship. This decouples product creation from the code that uses the product, making it easy to add new product types by adding new subclasses.