在页175,有一个巧克力锅炉类的例子.像这样的东西:
public class ChocolateBoiler {
private boolean empty;
private boolean boiled;
public ChocolateBoiler {
empty = true;
boiled = false;
}
// and then three methods to fill, drain and boil which changes the
// status of these two flag depending of situation
}
Run Code Online (Sandbox Code Playgroud)
在"脑力"一节中,他们提出了一个问题:如果在应用程序中创建了多个ChocolateBoiler实例,那么问题会出现什么问题?
我不确定这堂课有什么问题.为什么我们在这里引入单例模式?这两个标志不是静态的,因此每个实例都有一个.那么如何创建多个实例会让事情搞糟?