How can I implement an abstract singleton class in Java?

前端 未结 6 446
日久生厌
日久生厌 2020-12-15 16:48

Here is my sample abstract singleton class:

public abstract class A {
    protected static A instance;
    public static A getInstance() {
        return ins         


        
6条回答
  •  半阙折子戏
    2020-12-15 17:39

    Abstract Singleton? Doesn't sound viable to me. The Singleton pattern requires a private constructor and this already makes subclassing impossible. You'll need to rethink your design. The Abstract Factory pattern may be more suitable for the particular purpose.

提交回复
热议问题