8.9(목) C++ - Proxy의 활용

from Study/C++ 2007/08/13 16:00 view 41914

#include <iostream>

using namespace std;

// C# : .Net Remoting

// JAVA : RMI

// COM : 분산COM

// 원격제어에 있는 메소드를 호출하겠다.

// proxy ( foo(1, 2) ) -> 마샬리-> 스텁-> 서버측 foo호출

 

// proxy를 제대로 써보자.

class Printer

{

public:

       Printer()

       {

             cout << "Warming up" << endl;

             for ( int i = 0; i < 1000000000; ++i );

             cout << "OK..." << endl;

       }

 

       void print() const

       {

             cout << "Printer::print" << endl;

       }

       void print_time() const

       {

             cout << "print_time()" << endl;

       }

};

 

// printer를 대신 할 proxy를 만든다.

// 대행자를 만들어서 사용하도록 하자.

class PrinterProxy

{

       Printer* p;

public:

       void print_time() const

       {

             cout << "print_time()" << endl;

       }

       void print() const

       {

             // 진짜 객체가 필요하면 만들어서 사용한다.

             if ( p == 0 )

                    p = new Printer;

             p->print();

       }

};

 

 

void main()

{

       Printer p;

       p.print_time();

}

 

Tag |

Trackback Address :: 이 글에는 트랙백을 보낼 수 없습니다