Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created March 21, 2025 18:15
Show Gist options
  • Save trikitrok/491b21f6e9968375bbea034738029864 to your computer and use it in GitHub Desktop.
Save trikitrok/491b21f6e9968375bbea034738029864 to your computer and use it in GitHub Desktop.
export class MessageRouter {
public route(message: Message): void {
//!! ouch... x(
ExternalRouter.getInstance().sendMessage(message);
}
}
export class ExternalRouter { // another Singleton! x(
private static instance: ExternalRouter | null = null;
private constructor() {
// initialize stuff
}
public static getInstance(): ExternalRouter {
if (this.instance === null) {
this.instance = new ExternalRouter();
}
return this.instance;
}
// more code...
public sendMessage(message: Message): void {
// interesting code to send the message
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment