58. 静态工厂方法

 

参考:https://www.jianshu.com/p/ceb5ec8f1174spa

          https://www.jianshu.com/p/fa15f63d399a3d

1.定义

         用一个静态方法来对外提供自身实例的方法,即为咱们所说的静态工厂方法(Static factory method)code

 

//私有化构造方法
private Student() {};
private static volatile  Student student;

//静态工厂方法
public static Student getStudentInstance() {
    return  new Student();
}

如:blog

2.优势

 

相关文章
相关标签/搜索