Created
December 8, 2023 15:00
-
-
Save suhailgupta03/acbc36d935b32deabcfcf56341f79d6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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