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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
爱范儿
爱范儿
WordPress大学
WordPress大学
V
V2EX
宝玉的分享
宝玉的分享
小众软件
小众软件
B
Blog
博客园 - 叶小钗
U
Unit 42
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
H
Help Net Security
P
Proofpoint News Feed
D
Docker
Microsoft Security Blog
Microsoft Security 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;