Static factory methods are an alternative to public constructors in OO languages that support class-level methods. They were popularized by Joshua Bloch in his book, Effective Java. Static factory methods are *not* one of the Gang of Four [design-patterns]. The [abstract-factory] and [factory-method] patterns are entirely separate.
Joshua Bloch has promoted the idea of static factory methods since at least 2001 with the first edition of his Effective Java book. He writes,
The traditional way for a class to allow a client to obtain an instance is to provide a public constructor. There is another technique that should be a part of every programmer’s toolkit. A class can provide a public static factory method, which is simply a static method that returns an instance of the class.
Bloch offers several reasons for using static factory methods instead of constructors.
- One advantage of static factory methods is that, unlike constructors, they have names.
- A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they’re invoked.
- A third advantage of static factory methods is that, unlike constructors, they can return an object of any subtype of their return type.
- A fourth advantage of static factories is that the class of the returned object can vary from call to call as a function of the input parameters.
- A fifth advantage of static factories is that the class of the returned object need not exist when the class containing the method is written.
There are caveats to static factory methods, however.
- The main limitation of providing only static factory methods is that classes without public or protected constructors cannot be subclassed.
- A second shortcoming of static factory methods is that they are hard for programmers to find.
Note the Gang of Four published two factory design-patterns, named abstract-factory and factory-method, which are entirely different from static factory methods. There are more factory patterns outside the GoF book, so the term "factory" by itself is ambiguous.