Created
March 21, 2025 18:31
-
-
Save trikitrok/23ae8f61221c7cc5f8cf605247f67569 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
// a utility class :( | |
export class BankingServices { | |
public static updateAccountBalance(userId: number, amount: Money): void { | |
// some code to update the account balance | |
} | |
// more methods... | |
} | |
export class User { | |
private id: number; | |
constructor(id: number) { | |
this.id = id; | |
} | |
// more code... | |
public updateBalance(amount: Money): void { | |
// using the utility class :( | |
BankingServices.updateAccountBalance(this.id, amount); | |
} | |
// more code... | |
} | |
////////////////////////////////////////////// | |
// Introduce instance delegator in the utility class | |
export class BankingServices { | |
public static updateAccountBalance(userId: number, amount: Money): void { | |
// some code to update the account balance | |
} | |
//!! the instance delegator <- now we can Subclass & Override Method here! | |
public updateBalance(userId: number, amount: Money): void { | |
// it calls the static method | |
BankingServices.updateAccountBalance(userId, amount); | |
} | |
// more methods... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment