Search⌘ K
AI Features

Factory Method Pattern

Explore the factory method pattern to understand how it enables flexible object creation by delegating instantiation to subclasses. Learn to reduce tight coupling and improve code extensibility using Java examples involving aircraft variants. This lesson clarifies differences from simple factories and shows practical applications in software frameworks.

What is it ?

A factory produces goods, and a software factory produces objects. Usually, object creation in Java takes place like so:

SomeClass someClassObject = new SomeClass();

The problem with the above approach is that the code using the SomeClass's object, suddenly now becomes dependent on the concrete implementation of ...