Reputation: 30857
I have a singleton
logger which is used by many threads at run-time for logging purposes. I need different types of it so I decided to move changeable part into protected
methods and inherit from it.
Is there anything special with singleton
classes in inheritance (any considerations we don't have with regular classes)?
Upvotes: 0
Views: 286
Reputation: 33139
Singletons should be sealed, period. Otherwise they may not really be singletons in practice.
Of course you may use an IOC container such as StructureMap, Autofac or Castle Windsor to manage the lifestyle of your class; then you don't have to write it as a singleton, just declare it in the IOC container as a singleton.
That being said, looking at your particular example (you want logging), you may not really need a singleton class for that. You only use singleton if there is a very good reason to -- such as severe overhead when creating the object. But opening a text file for writing does not count as significant overhead...
Upvotes: 1