惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
Engineering at Meta
Engineering at Meta
有赞技术团队
有赞技术团队
月光博客
月光博客
M
MIT News - Artificial intelligence
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
雷峰网
雷峰网

博客园 - 酸辣大白菜

排序算法 终结版 (C#) --数据结构 做人学会说NO,写程序学会说NULL。----------设计模式 用于主题检测的临时日志(bf1783d2-27ab-4079-a1c6-08a661824368 - 3bfe001a-32de-4114-a6b4-4005b770f6d7) windows mobile网络设备 ------------- DMProcessConfigXML android 系统配置 常用命令 - linux qt 信号与槽机制 用于主题检测的临时日志(b9c62a98-6395-4fa6-b30d-70521beaf329 - 3bfe001a-32de-4114-a6b4-4005b770f6d7) 无绳电话系统 C++ 数据类型转换 关于内存泄漏检测 发布一个边看电子书边听英语的小工具 xml 解析库 msxml6.dll IE 8 与vs2005的兼容性问题 c++ vector用法 关于msxml.dll 音频驱动的3种模式 download WM6.5.3 SDK about CreateFileMapping on wince about MarshalledBuffer
C++ 工厂模式
酸辣大白菜 · 2010-06-28 · via 博客园 - 酸辣大白菜

定义抽象类

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;