Skip to main content

Creational Design Patterns

Factory Method & Abstract Factory

0:00
LearnStep 1/4

Factory Method Pattern

Factory Method: Flexible Object Creation

Factory Method defines an interface for creating objects but lets subclasses decide which class to instantiate.

Problem It Solves

When you don't know the exact type of object you need until runtime, or when object creation logic is complex.

Simple Factory (Not GoF, but Common)

python

True Factory Method Pattern

python

Real-World Example: Payment Processing

python

Benefits

  • Decouples object creation from usage
  • Easy to add new types without modifying existing code (Open/Closed Principle)
  • Centralizes object creation logic
  • Makes code more testable