public class Book
{
private static Book book;
private Book(){
}
public static Book getBook(){
if(book == null){
return new Book();
}
return book;
}
}
单子(单例)模式,顾名思义,就是一个类只创建一个对象,
public class Book
{
private static Book book;
private Book(){
}
public static Book getBook(){
if(book == null){
return new Book();
}
return book;
}
}