republicanfactory.cpp

来自「设计模式实例: 工厂方法(Factory)源代码)」· C++ 代码 · 共 40 行

CPP
40
字号
// RepublicanFactory.cpp: implementation of the RepublicanFactory class.
//
//////////////////////////////////////////////////////////////////////

#include "RepublicanFactory.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

RepublicanFactory::RepublicanFactory()
{

}

RepublicanFactory::~RepublicanFactory()
{

}

Officer*  RepublicanFactory::CreateOfficer(OfficialType type)
{
	if(m_Officer!=NULL)
		delete m_Officer;
	switch(type)
	{
		case PresidentType:
			m_Officer=new President("Republic");
			break;
		case AttorneyGeneralType:
			m_Officer=new AttorneyGeneral("Republic");
			break;
		case MinorityPartyCongressPersonType:
		    m_Officer=new MinorityPartyCongressPerson("Republic");
			break;
		default:
			break;
	}
	return m_Officer;
}

⌨️ 快捷键说明

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