Skip to content

Instantly share code, notes, and snippets.

@zehan12
Last active October 18, 2024 19:43
Show Gist options
  • Select an option

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

Select an option

Save zehan12/e628fdcd4d8a3b26fbf0dd927ef4d605 to your computer and use it in GitHub Desktop.
class User {
constructor(name) {
this.name = name;
}
}
class UserRepository {
save(user) {
console.log(`Saving ${user.name} to the database.`);
}
}
class WelcomeMailer {
sendEmail(user) {
console.log(`Sending welcome email to ${user.name}.`);
}
}
const user = new User("Zehan");
const repo = new UserRepository();
const mailer = new WelcomeMailer();
repo.save(user); // Saving Zehan to the database.
mailer.sendEmail(user); // Sending welcome email to Zehan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment