Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created December 8, 2023 15:00
Show Gist options
  • Save suhailgupta03/acbc36d935b32deabcfcf56341f79d6a to your computer and use it in GitHub Desktop.
Save suhailgupta03/acbc36d935b32deabcfcf56341f79d6a to your computer and use it in GitHub Desktop.
// SINGLE RESPONSIBILITY PRINCIPLE
class User {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
displayUserInfo() {
console.log(`User name is ${this.name}`);
}
}
class UserRepository {
constructor(user) {
this.user = user;
}
saveUserDetails() {
db.save(this.user);
}
}
class Email {
sendEmail(user) {
console.log(`Email sent to ${user.name}`);
}
}
const user = new User('John');
const userRepository = new UserRepository(user);
userRepository.saveUserDetails();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment