FAQ: What are “Factory methods” and “Factory patterns” in Java?

An odd concept to some, but it’s actually quite straightforward — these are methods (functions) that are declared to return instances of some base class (especially an abstract base class) but actually return instances of a derived class are often called “Factory Methods“, because they produce objects.
The associated design pattern is called the Factory Pattern. Using the Factory pattern is an excellent way to hide implementation details from parts of a program that don’t need to know them. This kind of hiding tremendously simplifies program maintenance.