Skip to main content
Design Patterns design recommended

Factory Pattern

The Factory Pattern provides a way to create objects without exposing instantiation logic, using a common interface. Includes Simple Factory, Factory Method, and Abstract Factory variations.

Difficulty
intermediate
Read time
1 min read
Version
v1.0.0
Confidence
established
Last updated

Quick Reference

Factory Pattern: Create objects without exposing instantiation logic. Simple Factory (static method), Factory Method (subclass decides), Abstract Factory (families of related objects). Use for complex construction, conditional creation, or decoupling client from concrete classes.

Use When

  • Object creation logic is complex
  • Need to create different types based on runtime conditions
  • Want to decouple client from concrete implementations
  • Creating families of related objects

Skip When

  • Simple object construction (just use new/constructor)
  • Single concrete implementation
  • No variation in object creation

Factory Pattern

The Factory Pattern provides a way to create objects without exposing instantiation logic, using a common interface. Includes Simple Factory, Factory Method, and Abstract Factory variations.

Tags

factory design-patterns creational object-creation clean-code

Discussion