Summary

The intent of the FACTORY METHOD pattern is to define the interface for creating a new object so that a service provider decides which class to instantiate instead of clients. This pattern occurs in the Java class libraries and is common in application code.

You can also apply FACTORY METHOD when you want to introduce a parallel class hierarchy. This can help keep a set of classes from becoming bloated with many different aspects of behavior. FACTORY METHOD lets you connect parallel hierarchies by letting subclasses in one hierarchy determine which class to instantiate in the corresponding hierarchy.

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.