定义抽象类
class IParser
{
public:
virtual bool GetStructData(PBYTE bufIn,DWORD bufLength,string cxmlString) = 0;
virtual string CreateXMLData(PBYTE bufIn,DWORD bufLength) = 0;
};
派生类:
class CGetUserInfoParser :public IParser
{
public:
bool GetStructData(PBYTE bufIn,DWORD bufLength,string cxmlString);
string CreateXMLData(PBYTE bufIn,DWORD bufLength);
CGetUserInfoParser();
~CGetUserInfoParser();
};
class CRegisterParser : public IParser
{
public:
virtual bool GetStructData(PBYTE bufIn,DWORD bufLength,string cxmlString);
virtual string CreateXMLData(PBYTE bufIn,DWORD bufLength);
};
抽象工厂:
class ParserFactory
{
public:
static IParser* CreateParser(_EActionType type);
protected:
//constructor/destructoric
};
IParser* ParserFactory::CreateParser(_EActionType type)
{
switch(type)
{
case _EActionType::E_ACTION_getUserInfo:
return new CGetUserInfoParser();
break;
case _EActionType::E_ACTION_handsetAuthenticate:
return new CHandsetAuthenticateParser ();
break;
case _EActionType::E_ACTION_register:
return new CRegisterParser();
break;
default:
return NULL;
}
}
调用:
IParser* poRecord;
poRecord=ParserFactory::CreateParser(_EActionType::E_ACTION_handsetAuthenticate);
poRecord->GetStructData();
delete poRecord;
原文链接: https://www.cnblogs.com/sea918/archive/2010/06/28/1766807.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/12233
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!