← Back to design patterns map
🏭
Design Pattern

Factory Method

Create objects through a factory instead of calling constructors directly.

creational

Visual Diagram

create(type)
email -> EmailNotifier
sms   -> SMSNotifier
push  -> PushNotifier

When To Use

  • ->Notification system with email, SMS, and push
  • ->Payment gateway selection
  • ->Logger transport creation
  • ->Database driver selection
Used in: Express middleware factories, Sequelize dialects
factory.js

Live Editor

Loading...

Output

Run code to see output...