Created
July 15, 2020 22:50
-
-
Save richartkeil/71b1919a2ada2f70e0af9c47145ab0d1 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
interface Broadcaster { | |
send(event: Event, user: User) | |
} | |
class EmailBroadcaster implements Broadcaster { | |
send(event: Event, user: User) { | |
const description = `New event ${event.name} occured at ${event.getTimestamp()}` | |
emailService.send({ to: user.email, subject: event.name, body: description }) | |
} | |
} | |
class NotificationHandler { | |
constructor(private broadcaster: Broadcaster) {} | |
broadcast(event: Event, user: User) { | |
this.broadcaster.send(event, user) | |
} | |
} | |
function onAccountCreated(event: Event, user: User) { | |
const notifications = new NotificationHandler(new EmailBroadcaster()) | |
notifications.broadcast(event, user) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment