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

📄 autohouse.cpp

📁 深入浅出设计模式(书配套c++源代码)。包含20个设计模式的c++实现。
💻 CPP
字号:
#include "AutoHouse.hpp"

using namespace HeadFirstDesignPatterns::Mediator::AutoHouse;

// The 'Mediator' pattern is discussed on page 622 in 'Head First Design Patterns'.
//
// As always, my intent is to implement the example as described in the book; however,
// there are some embellishments: WeatherStation and automation.
//
// The WeatherStation knows if it is raining and automation is accomplished by two
// variables: 'interval' and 'iterations' specifying the length of a virtual day
// and the number of days to simulate respectively. The default is a simulated
// (yet accelerated) 24 hour day that runs for a simulated week. 
//
// You can override these values with command-line parameters.

unsigned long interval = 12;	// length of day (in seconds)
unsigned long iterations = 7;	// number of days to simulate

int main( int argc, char* argv[] ) {

	if( argc > 1 ) {	// argument[1]=length of day (in seconds)
		std::stringstream( argv[1] ) >> interval;
	}
	if( argc > 2 ) {	// argument[2]=number of days
		std::stringstream( argv[2] ) >> iterations;
	}

	// TODO: Mediator could/should be implemented as a 'Singleton'
	std::auto_ptr< Mediator > mediator( new Mediator( iterations ) );

	mediator->on( interval );

	return 0;
}

⌨️ 快捷键说明

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