Created
April 1, 2024 04:50
-
-
Save Akash52/6c63029beb928d123533dfb95c469cde 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 segregation for user actions | |
interface UserActions { | |
login(): void; | |
logout(): void; | |
} | |
// Separate interfaces for specific actions | |
interface EmergencyContactable { | |
notifyEmergencyContact(message: string): void; | |
} | |
// User class implementing specific actions | |
class User implements UserActions, EmergencyContactable { | |
login(): void { | |
console.log("User logged in"); | |
} | |
logout(): void { | |
console.log("User logged out"); | |
} | |
notifyEmergencyContact(message: string): void { | |
console.log("Notifying emergency contact: " + message); | |
} | |
} | |
// Creating an instance of the User class | |
const user = new User(); | |
// Invoking methods | |
user.login(); | |
user.notifyEmergencyContact("This is an emergency message!"); | |
user.logout(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment