Is it possible to inherit a singleton class and override its method in TypeScript? Or is there any other way to implement this type of scenario in TypeScript?
// Parent Class
export class SFSCommands {
static instance: SFSCommands;
protected constructor() {
if (SFSCommands.instance) {
return SFSCommands.instance;
}
setInterval(() => {
this.initSfsCommands('sss');
}, 2000);
}
static getInstance() {
if (!SFSCommands.instance) {
SFSCommands.instance = new SFSCommands();
}
return SFSCommands.instance;
}
initSfsCommands(e: any) {
console.log('comming in service');
}
}
//**** Child Class ***********
import { SFSCommands } from '../utility/sfscommands';
export abstract class GameModel extends SFSCommands {
roomName: string;
constructor() {
super();
console.log(this);
}
// called from child when game component initialized
initSfsCommands(event: any) {
console.log('game model');
}
}
I call SFSCommands.getInstance() from my app.component.ts file