Factory Methods Styled in Java
Factory Methods Styled in Java
A Factory Method is a design pattern in object-oriented programming that provides an interface for
creating objects in a superclass, but allows subclasses to alter the type of objects that will be
created. Factory Methods are commonly used in real-world projects to promote loose coupling and
improve code maintainability.
1. Simple Factory
2. Factory Method Pattern
3. Abstract Factory
4. Singleton Factory
5. Parameterized Factory
Simple Factory
Definition: A method that returns an instance of different classes based on input parameters.
Definition: Provides an interface for creating objects but allows subclasses to decide which class to
instantiate.
Page 1
Factory Methods in Java - Types and Real-Time Usage
Abstract Factory
Definition: A factory of factories. It creates families of related objects without specifying their
concrete classes.
Singleton Factory
Definition: A factory that ensures only one instance exists and provides a global access point to it.
private DatabaseConnectionFactory() {}
Parameterized Factory
Definition: A factory method that takes parameters to customize the object creation.
Page 2
Factory Methods in Java - Types and Real-Time Usage
Page 3