Skip to content

Instantly share code, notes, and snippets.

@zehan12
Created October 18, 2024 20:32
Show Gist options
  • Select an option

  • Save zehan12/bfe0eeb4b7881e4684ea618474580599 to your computer and use it in GitHub Desktop.

Select an option

Save zehan12/bfe0eeb4b7881e4684ea618474580599 to your computer and use it in GitHub Desktop.
class Notification {
constructor(service) {
this.service = service;
}
notify(message) {
this.service.send(message);
}
}
class EmailService {
send(message) {
console.log(`Sending email: ${message}`);
}
}
class SMSService {
send(message) {
console.log(`Sending SMS: ${message}`);
}
}
const notification = new Notification(new SMSService());
notification.notify("Order shipped"); // Sending SMS: Order shipped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment