Can we inherit singleton class?
It depends on implementation. Singletons usually have private constructor and possibly marked sealed
, if it is so then you can't. If it is at least protected you can. If you just inherit from singleton class, result will not be singleton so you should follow the pattern and make it also singleton.
Yes you can. Keep base class constructor protected (and not private).
Then derived class can be instantiated but base class cannot be (even inside function definitions of derived class). I've tried this and it works well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With