아래는 추상 팩토리 패턴의 예제로 C 스타일의 예제가 없어서 만들어 봤다.
class CDBProcess
{
public:
virtual void LoadCharacter() = 0;
};
class CSDBProcess : public CDBProcess
{
void LoadCharacter()
{
printf("SDB\n");
}
};
class CXDBProcess : public CDBProcess
{
void LoadCharacter()
{
printf("XDB\n");
}
};
class CDBProcessFac
{
public:
virtual CDBProcess* CreateProcess() = 0;
};
class CXDBProcessFac : public CDBProcessFac
{
CDBProcess* CreateProcess()
{
return new CXDBProcess;
}
};
class CSDBProcessFac : public CDBProcessFac
{
CDBProcess* CreateProcess()
{
return new CSDBProcess;
}
};
void main()
{
CDBProcessFac *pCDBProcessFac = new CSDBProcessFac;
CDBProcess *pCDBProcess = pCDBProcessFac->CreateProcess();
pCDBProcess->LoadCharacter();
}
'Design Pattern' 카테고리의 다른 글
[Design pattern] Master-Slave (0) | 2013.02.21 |
---|---|
[Design pattern] Whole-Part (0) | 2013.02.21 |
[Design pattern] 팩토리 매서드 패턴 (0) | 2013.02.20 |
[Design pattern] 빌더 패턴 (0) | 2013.02.20 |
[Design Pattern] Thread-Safe Singleton (0) | 2013.02.13 |