单件模式,又称单例模式,确保一个类只有一个实例,并提供全局访问点。

  单件模式是比较简单且容易理解的一种设计模式。只有一个实例,通常的做法。。。TODO

  类图比较简单,如下所示:

  设计模式----创建型型模式之单件模式(Singleton pattern) 

  示例代码:

  懒汉模式(初始化时就创建对象):

public class Singleton {
    private final static Singleton uniqueInstance= new Singleton();
     
    private Singleton() {}
 
    public static Singleton getInstance() {
        return uniqueInstance;
    }
  }
View Code  

相关文章:

  • 2021-07-11
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-03-02
  • 2022-01-31
  • 2022-12-23
猜你喜欢
  • 2021-04-30
  • 2021-08-02
  • 2022-01-24
  • 2021-06-09
  • 2022-02-11
  • 2022-01-22
相关资源
相似解决方案