Skip to main content

Overview

Category

Creational Design Pattern

Purpose

Encapsulate object creation logic

Problem Statement

The Challenge

We need to create different classifier and strategy objects based on runtime configuration:
  1. Encapsulate creation logic: Complex initialization
  2. OCP Compliance: Add new types without modifying factory code
  3. Centralized creation: Single point of change
Adding a new classifier requires ONLY:
✅ Open for extension, closed for modification

Solution: Dictionary Map Factory

Factory vs Singleton: Factory creates new instances on each call. This prevents state leakage between requests.

Benefits

OCP Compliance

Add new types by adding to registry only

Encapsulation

Complex creation logic hidden from client

Centralized

Single point of change for object creation

Configurable

Runtime selection via environment variables