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

推荐订阅源

T
Tailwind CSS Blog
博客园 - 【当耐特】
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
B
Blog
有赞技术团队
有赞技术团队
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
Jina AI
Jina AI
Vercel News
Vercel News
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
The Cloudflare Blog
V
V2EX
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
腾讯CDC

博客园 - 酸辣大白菜

排序算法 终结版 (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;