democratfactory.cpp

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

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

#include "DemocratFactory.h"

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

DemocratFactory::DemocratFactory()
{

}

DemocratFactory::~DemocratFactory()
{

}

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

⌨️ 快捷键说明

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