Created
August 19, 2020 05:15
-
-
Save velotiotech/58cec3d85b881ebbaff81a1ebc20b96e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PushNotification { | |
constructor(sendTo, message) { | |
this.sendTo = sendTo; | |
this.message = message; | |
} | |
} | |
class EmailNotification { | |
constructor(sendTo, cc, emailContent) { | |
this.sendTo = sendTo; | |
this.cc = cc; | |
this.emailContent = emailContent; | |
} | |
} | |
// Notification Factory | |
class NotificationFactory { | |
createNotification(type, props) { | |
switch (type) { | |
case 'email': | |
return new EmailNotification(props.sendTo, props.cc, props.emailContent); | |
case 'push': | |
return new PushNotification(props.sendTo, props.message); | |
} | |
} | |
} | |
// usage | |
const factory = new NotificationFactory(); | |
// create email notification | |
const emailNotification = factory.createNotification('email', { | |
sendTo: 'receiver@domain.com', | |
cc: 'test@domain.com', | |
emailContent: 'This is the email content to be delivered.!', | |
}); | |
// create push notification | |
const pushNotification = factory.createNotification('push', { | |
sendTo: 'receiver-device-id', | |
message: 'The push notification message', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment