定义抽象类

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;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2021-09-13
  • 2021-11-19
  • 2021-11-17
猜你喜欢
  • 2022-01-10
  • 2021-12-03
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
相关资源
相似解决方案