A factory method is a method in a subclass that creates an object. Factory Method pattern defines a Creator interface with Factory Methods (“create” methods) that are implemented by sub-classes. According to Design Patterns by GoF, the intent of Factory Method is to,
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method (pattern) lets a class defer instantiation to subclasses.
‘Singleton’ is a fancy word for ‘global variable.’
The intent of Singleton:
Ensure a class only has one instance, and provide a global point of access to it. - GOF
All singleton implementations offer NO public constructor but only private constructor to enforce non-instantiability. In Java, however, because a private constructor can still be accessed through a backdoor of using reflection, you want to add extra check in the private constructor to guard against reflection vulnerability (see examples below).
What is Abstract Factory pattern and what is it for? According to Design Patterns by GoF, the intent of Abstract Factory is to,
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
What is Builder pattern and what is it for? According to Design Patterns by GoF, the intent of Builder is to,
Separate the construction of a complex object from its representation so that the same construction process can create different representations.