© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
V. SarcarJava Design Patternshttps://doi.org/10.1007/978-1-4842-7971-7_3

3. Factory Method Pattern

Vaskaran Sarcar1  
(1)
Garia, Kolkata, India
 

This chapter covers the Factory Method pattern. The Factory Method pattern will make more sense to you if you understand the pros and cons of the Simple Factory pattern, which is covered in Chapter 2.

GoF Definition

It defines an interface for creating an object, but lets subclasses decide which class to instantiate. The Factory Method pattern lets a class defer instantiation to subclasses.

Concept

Here you start with an abstract creator class (often called a creator) that defines the basic structure of an application, ...

Get Java Design Patterns: A Hands-On Experience with Real-World Examples 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.