Design Pattern Examples
Overview of object-oriented design patterns
Proxy_Exercise.cpp
Go to the documentation of this file.
1
6
7#include <iostream>
8
9#include "helpers/formatstring.h"
10
11#include "Proxy_Exercise.h"
12#include "Proxy_Class.h"
13
15{
16
34 // ! [Using Proxy in C++]
36 {
37 std::cout << std::endl;
38 std::cout << "Proxy Exercise" << std::endl;
39
40 std::cout << " Getting proxy object..." << std::endl;
41 std::unique_ptr<IWorkByProxy> proxyObject = Proxy_Classes_Container::CreateProxy();
42
43 std::cout << " Calling Dowork() on proxy..." << std::endl;
44 std::string output = proxyObject->DoWork("Initial call");
45 std::cout << Helpers::formatstring(" Output from proxy = \"%s\"", output.c_str()) << std::endl;
46
47 std::cout << " Calling Dowork() on proxy..." << std::endl;
48 output = proxyObject->DoWork("Second call");
49 std::cout << Helpers::formatstring(" Output from proxy = \"%s\"", output.c_str()) << std::endl;
50
51 std::cout << " Calling Dowork() on proxy..." << std::endl;
52 output = proxyObject->DoWork("Third call");
53 std::cout << Helpers::formatstring(" Output from proxy = \"%s\"", output.c_str()) << std::endl;
54
55 std::cout << " Done." << std::endl;
56 }
57 // ! [Using Proxy in C++]
58
59} // end namespace
Declaration of the IWorkByProxy interface and the Proxy_Classes_Container class used in the Proxy Pat...
static std::unique_ptr< IWorkByProxy > CreateProxy()
Retrieve a new instance of the proxy class.
Declaration of the Proxy_Exercise() function as used in the Proxy Pattern.
The namespace containing all Design Pattern Examples implemented in C++.
void Proxy_Exercise()
Example of using the Proxy design pattern.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....