Last active
June 3, 2020 16:01
-
-
Save richartkeil/3e20c422bb804b8fb832f1e5bab4805b 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 EmailBroadcaster { | |
broadcast(event: Event); | |
} | |
class AnonymousEmailBroadcaster implements EmailBroadcaster { | |
constructor(protected user: User) {} | |
broadcast(event: Event) { | |
// Send email with event details to user. | |
} | |
} | |
class SubscriptionEmailBroadcaster implements EmailBroadcaster { | |
constructor(protected user: SubscribedUser) {} | |
broadcast(event: Event) { | |
// Send email with subscription information | |
// and event details to user. | |
} | |
} | |
function onAccountCreated(event: Event) { | |
const user = getCurrentUser(); // returns type User or SubscribedUser | |
(new AnonymousEmailBroadcaster(user)).broadcast(event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment