7
← Back to Pattern Arsenal
creational

Simple Factory

must know

Stage 1: Problem

Problem

Not a GoF pattern, but the most common "factory" you will encounter in real code and interviews. Often just called "the Factory Pattern."

You are building a notification service for an e-commerce platform. When an order ships, the system sends a notification. The channel depends on user preferences stored in the database: some want email, some want SMS, some want push notifications.

Right now the code that dispatches notifications looks like a mess of conditionals scattered across three different services. Every time product adds a new channel (WhatsApp is next quarter), you touch five files.

Your task: How would you centralize the creation of the right notification handler based on a channel string, so adding a new channel means changing exactly one place?

Write your approach before continuing.


1 / 10 — Problem