336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
** CClock.h
#ifndef __CCLOCK_H_ #define __CCLOCK_H_ #includeusing namespace std; class CClock { public: virtual void Draw() = 0; }; class CAnalogClock : public CClock { public: virtual void Draw() { cout << "아날로그 시계를 그린다." << endl; } }; class CDigitalClock : public CClock { public: virtual void Draw() { cout << "디지털 시계를 그린다." << endl; } }; #endif
** CClockDateDecorator.h
#ifndef __CCLOCK_DATE_DECORATOR_H_ #define __CCLOCK_DATE_DECORATOR_H_ #include#include "CClock.h" using namespace std; class CClockDateDecorator : public CClock { public: virtual void Draw(); public: CClockDateDecorator (CClock* a_pClock) : m_pClock(a_pClock) { } virtual ~CClockDateDecorator() { if (m_pClock) delete m_pClock; } private: CClock* m_pClock; }; void CClockDateDecorator::Draw() { m_pClock->Draw(); cout << "날짜를 그린다" << endl; } class CWorldDecorator : public CClock { public: virtual void Draw(); public: CWorldDecorator (CClock* a_pClock, char* a_szCity) : m_pClock(a_pClock) { m_pCity = new char [strlen(a_szCity) + 1]; strcpy(m_pCity, a_szCity); } virtual ~CWorldDecorator() { if (m_pClock) delete m_pClock; if (m_pCity) delete m_pCity; } private: CClock* m_pClock; char* m_pCity; }; void CWorldDecorator::Draw() { m_pClock->Draw(); cout << m_pCity <<" 도시의 시간 표시를 한다" << endl; } #endif
** main.cpp
CClock* pDataClock = new CClockDateDecorator (new CAnalogClock); //pDataClock->Draw(); CClock* pWorldClock = new CWorldDecorator (pDataClock, "seoul"); pWorldClock->Draw(); delete pDataClock; delete pWorldClock;
'ⓟrogramming > Design Pattern' 카테고리의 다른 글
[아임구루] Design Pattern 3일차 (0) | 2016.02.17 |
---|---|
[아임구루] Design Patter 2일차 (0) | 2016.02.16 |
[아임구루] Design Pattern 1일차 (0) | 2016.02.15 |
Command(커멘드) Pattern (0) | 2011.02.28 |
스테이트 패턴(State Pattern) (0) | 2011.02.24 |