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

📄 chocolateboiler.hpp

📁 深入浅出设计模式(书配套c++源代码)。包含20个设计模式的c++实现。
💻 HPP
字号:
#ifndef	_HFDP_CPP_SINGLETON_CHOCOLATE_BOILER_HPP_
#define _HFDP_CPP_SINGLETON_CHOCOLATE_BOILER_HPP_

#include "Chocolate.hpp"

namespace HeadFirstDesignPatterns {
namespace Factory {
namespace Singleton {

class ChocolateBoiler {

	private: static ChocolateBoiler* _uniqueInstance;
	private: bool _empty;
	private: bool _boiled;
  
	private: ChocolateBoiler( const ChocolateBoiler& ); // Disable copy constructor
	private: void operator=( const ChocolateBoiler& ); // Disable assignment operator

	private: ChocolateBoiler() {
		_empty = true;
		_boiled = false;
	}
	private: ~ChocolateBoiler() {
		_uniqueInstance = 0;
	}
  	public: static ChocolateBoiler* getInstance() {
		if( _uniqueInstance == 0 ) {
			std::cout << "Creating unique instance of Chocolate Boiler" << std::endl;
			_uniqueInstance = new ChocolateBoiler();
		}
		std::cout << "Returning instance of Chocolate Boiler"<< std::endl;
		return _uniqueInstance;
	}
	public: void fill() {	// fill the boiler with a milk/chocolate mixture
		if( isEmpty() ) {
			_empty = false;
			_boiled = false;
		}
	}
	public: void drain() {	// drain the boiled milk and chocolate
		if( !isEmpty() && isBoiled() ) {
			_empty = true;
		}
	}
	public: void boil() {	// bring the contents to a boil
		if( !isEmpty() && !isBoiled() ) {
			_boiled = true;
		}
	}
	public: bool isEmpty() const {
		return _empty;
	} 
	public: bool isBoiled() const {
		return _boiled;
	}
};

} // namespace Singleton
} // namespace Factory
} // namespace HeadFirstDesignPatterns

#endif 

⌨️ 快捷键说明

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