336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

** 패턴 그리고 객체지향적 코딩의 법칙 - Story 25_ 행동만 따로 떼어보자 **

** ICommand.h
#ifndef __ICOMMAND_H_
#define __ICOMMAND_H_

class ICommand
{
public:
  virtual void Execute() = 0;
};
#endif

** IWindow.h
#ifndef __IWINDOW_H_
#define __IWINDOW_H_
#include 

using namespace std;

class IWindow
{
public:
  void Show(char* a_pszSearchResult) {
    cout << "검색 결과 : " << a_pszSearchResult << endl;
  }
};
#endif

** IDicSerachParam.h
#ifndef __IDICSEARCH_PARAM_H_
#define __IDICSEARCH_PARAM_H_
//#include "type.h"
#include "IWindow.h"

class IDicSearchParam
{
public:
  //virtual EDICTYPE GetSerachDicType() = 0;
  virtual char* GetSerchWord () = 0;
  virtual IWindow* GetSearchOutputWindow() = 0;
};
#endif

** CDicSearchCommand.h
#ifndef __CDICSEARCH_COMMAND_H_
#define __CDICSEARCH_COMMAND_H_
#include "ICommand.h"
#include "IDicSerachParam.h"

class CDicSearchCommand : public ICommand
{
public: // ICommand
  virtual void Execute();
public:
  CDicSearchCommand (IDicSearchParam* a_pSearchParam) : m_pSearchParam(a_pSearchParam) {

  }

  virtual ~CDicSearchCommand() {
    if (m_pSearchParam)
      delete m_pSearchParam;
  }

protected:
  virtual char* InternalSearch(char* a_pszSearchWord) = 0;

private:
  void DisplaySerachResult (char* a_pszSearchResult);
private:
  IDicSearchParam* m_pSearchParam;
};
#endif

** CDicSearchCommand.cpp
#include "stdafx.h"
#include "CDicSearchCommand.h"

void CDicSearchCommand::Execute()
{
  char* pszSearchWord = m_pSearchParam->GetSerchWord();
  char* pszSearchResult = NULL;

  pszSearchResult = InternalSearch(pszSearchWord);

  DisplaySerachResult(pszSearchResult);

  if (pszSearchResult)
    delete pszSearchResult;
}

void CDicSearchCommand::DisplaySerachResult(char* a_pszSearchResult)
{
  IWindow* pWindow = m_pSearchParam->GetSearchOutputWindow();
  pWindow->Show(a_pszSearchResult);
}

** CEngDicSearchCommand.h
 
#ifndef __CENG_DIC_SEARCH_COMMAND_H_
#define  __CENG_DIC_SEARCH_COMMAND_H_
#include "CDicSearchCommand.h"
#include 

class CEngDicSearchCommand : public CDicSearchCommand
{
public:
  virtual char* InternalSearch(char* a_pszSearchWord);
public:
  CEngDicSearchCommand(IDicSearchParam* a_pSearchParam);
  virtual ~CEngDicSearchCommand() {}
};

CEngDicSearchCommand::CEngDicSearchCommand(IDicSearchParam* a_pSearchParam)
: CDicSearchCommand(a_pSearchParam)
{

}

char* CEngDicSearchCommand::InternalSearch(char* a_pszSearchWord)
{
  char* engSearchReult = new char[strlen("English Search Result") + 1];
  std::cout << "영어 사전 사이트를 검색 합니다..." << std::endl;
  strcpy(engSearchReult, "English Search Result");
  return engSearchReult;
}
#endif

** CDicCommandFactory.h
#ifndef __CDIC_COMMAND_FACTORY_H_
#define __CDIC_COMMAND_FACTORY_H_
#include "ICommand.h"
#include "IDicSerachParam.h"
#include "type.h"
#include "CEngDicSearchCommand.h"

class CDicCommandFactory
{
public:
  static ICommand* CreateCommand (EDICTYPE a_eType, IDicSearchParam* a_pParam) {
    switch (a_eType)
    {
    case eDIC_ENG:
      return new CEngDicSearchCommand(a_pParam);
    }

    return NULL;
  }
};
#endif

** type.h
#ifndef __TYPE_H_
#define __TYPE_H_

typedef enum
{
  eDIC_ENG,
  eDIC_KOR,
  eDIC_ENC
}EDICTYPE;


#endif
블로그 이미지

뚱땡이 우주인

,