asks the factory for a notification — never uses new
2
Factory
create(channel)
decides which concrete class to build
3
Product · send(msg)
— no product yet —
Press notify(user) to build a product and deliver.
Client code — the code that calls itclient code: unchanged ✓
const n = NotificationFactory.create(user.channel);
n.send(msg); // caller never knows the concrete type
client code diff: 0 lines — switching channels never touches these two lines.
One line to build any channel
Pick a channel chip — 📧 Email, 💬 SMS, or 🔔 Push — then press notify(user). The factory builds the matching product and calls send(). Watch the client code panel above: it stays identical no matter which channel you pick.
▸The only place new lives is inside the factory. Add a whole new channel and the client code — those two lines above — never changes: Open/Closed in action.