⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chocolateboiler.java

📁 深入浅出设计模式
💻 JAVA
字号:
package headfirst.singleton.chocolate; public class ChocolateBoiler {	private boolean empty;	private boolean boiled;	private static ChocolateBoiler uniqueInstance;  	private ChocolateBoiler() {		empty = true;		boiled = false;	}  	public static ChocolateBoiler getInstance() {		if (uniqueInstance == null) {			System.out.println("Creating unique instance of Chocolate Boiler");			uniqueInstance = new ChocolateBoiler();		}		System.out.println("Returning instance of Chocolate Boiler");		return uniqueInstance;	}	public void fill() {		if (isEmpty()) {			empty = false;			boiled = false;			// fill the boiler with a milk/chocolate mixture		}	} 	public void drain() {		if (!isEmpty() && isBoiled()) {			// drain the boiled milk and chocolate			empty = true;		}	} 	public void boil() {		if (!isEmpty() && !isBoiled()) {			// bring the contents to a boil			boiled = true;		}	}  	public boolean isEmpty() {		return empty;	} 	public boolean isBoiled() {		return boiled;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -