Creational pattern · Visual logic

Factory Method: Move Creation Behind a Decision

Factory Method separates object creation from the workflow that uses the object, allowing a subtype or configuration to choose the concrete product.

Problem

Business logic repeatedly constructs concrete classes, so changing a product type forces edits across unrelated workflows.

Rule

Define a creation method that returns a shared product contract and let specialized creators choose the concrete result.

Run
  1. WORKFLOW asks its factory method for a compatible product.
  2. CREATOR selects and constructs the concrete implementation needed.
  3. WORKFLOW uses only the shared contract after creation completes.
Output

Creation decisions can evolve without spreading concrete constructor knowledge through the application.

Run it in the real world

A document export workflow requests a renderer while web, print, and mobile creators provide different renderers behind the same interface.

Go deeper

This is an original explanation and example inspired by Head First Design Patterns. The book covers the complete pattern, design principles, and implementation detail.

Retail links are not affiliate links yet. If that changes, this page will clearly disclose it.