Skip to content

Instantly share code, notes, and snippets.

@Akash52
Created April 1, 2024 04:50
Show Gist options
  • Save Akash52/6c63029beb928d123533dfb95c469cde to your computer and use it in GitHub Desktop.
Save Akash52/6c63029beb928d123533dfb95c469cde to your computer and use it in GitHub Desktop.
// 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