suppose i have a class i want as a singleton, and i write:
how do i now inherit this. the new inherited version needs to have a constructor that does something different.. i cant override getInstance in the child class, to call new ChildThing() because static methods cannot be overriddenCode:class Thing{ static Thing me; private Thing(string param){ //do some stuff } static getInstance(){ if(me ==null) me = new Thing(); return me; } }
Code:class ChildThing : Thing{ private ChildThing(string param){ //do some more stuff } static override getInstance(){ if(base.me ==null) base.me = new ChildThing(); return base.me; } }
so how does one write a singleton that is inheritable?




Reply With Quote