#include <iostream>

 

using namespace std;

 

#define interface class

 

interface IPhone {

public:

        virtual void send(const char*)=0;

};

 

class AnyCall : public IPhone {

public:

        void send(const char* n) {

               printf("calling %s with AnyCall...\n", n);

        }

};

 

class Cyon : public IPhone {

public:

        void send(const char* n) {

               printf("calling %s with Cyon...\n", n);

        }

};

 

class Sky : public IPhone {

public:

        void send(const char* n) {

               printf("calling %s with Sky...\n", n);

        }

};

 

class Person {

public:

        void userPhone(IPhone *p, const char *n) {

               p->send(n);

        }

};

 

 

int main(void) {

        Person p;

 

        AnyCall a;

        p.userPhone(&a, "000-0000-0000");

 

        Cyon c;

        p.userPhone(&c, "000-0000-0000");

 

        Sky s;

        p.userPhone(&s, "000-0000-0000");

 

        return 0;

}

'Developer > Design Patterns' 카테고리의 다른 글

GoF's Singleton (객체를 힙에 생성)  (0) 2014.05.17
Mayer's Singleton (객체를 정적변수로 선언)  (0) 2014.05.17
정적바인딩 / 동적바인딩  (0) 2014.05.17
C++ Thread 클래스 구현  (0) 2014.05.17
함수 포인터  (0) 2014.05.17
Posted by No names
,