EasyTypeScript

Factory Method

TypeScriptDesign PatternsCreationalFactory Method

Defer object creation to a factory function so calling code depends on an interface, never on concrete classes.

Implement `createNotification(type)`, returning an EmailNotification, SMSNotification or PushNotification — each with a send(message) method that formats the message differently.

solve(type, message) creates the right notification and returns send(message).

solve('sms', 'Hi')'[SMS] Hi'

Sample tests

Test #1Push notification
Input: ["push","Go"]
Output: "[Push] Go"
Test #2Email notification
Input: ["email","Hi"]
Output: "[Email] Hi"
Test #3SMS notification
Input: ["sms","Hi"]
Output: "[SMS] Hi"