Should we seal Singletons? Should we try to inherit from Singletons in the first place?

后端 未结 5 1286
夕颜
夕颜 2021-01-06 00:08

Should a Singleton class be allowed to have children? Should we seal it? What are the pro\'s and con\'s?

For being able to inherit from a Singleton class, we would h

5条回答
  •  失恋的感觉
    2021-01-06 01:06

    If you want to use inheritance in conjunction with the singleton pattern, you should put the inheritable state and behaviour into an abstract base class and define the singletons as (final) subclasses.

提交回复
热议问题