Patterns – Factory Method josedacruz, November 4, 2024November 4, 2024 Pattern – Factory Method What: Provides an interface for creating objects, but lets subclasses decide which class to instantiate. Best use case: When you need to create families of related objects without specifying their concrete classes. How it works: The Client class requests a document from the DocumentFactory by specifying the desired document type (e.g., “PDF” or “Word”). The DocumentFactory uses a conditional statement or a configuration file to determine which concrete Document class to instantiate based on the given type. The DocumentFactory creates the appropriate document object and returns it to the Client. The Client can then call the print() method on the returned document object to generate the desired output. This pattern promotes loose coupling between the client and the concrete product classes. The client doesn’t need to know the specific implementations of the Document classes. It simply interacts with the DocumentFactory to obtain the desired document. Related architecture architecturepatterns