Design Pattern Examples
Overview of object-oriented design patterns
Proxy_Exercise.c File Reference

Implementation of the Proxy_Exercise() function as used in the Proxy Pattern. More...

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "helpers/dynamicstring.h"
#include "Proxy_ProxyService.h"
#include "Proxy_Exercise.h"
Include dependency graph for Proxy_Exercise.c:

Go to the source code of this file.

Functions

void Proxy_Exercise (void)
 Example of using the Proxy design pattern.
 

Detailed Description

Implementation of the Proxy_Exercise() function as used in the Proxy Pattern.

Definition in file Proxy_Exercise.c.

Function Documentation

◆ Proxy_Exercise()

void Proxy_Exercise ( void  )

Example of using the Proxy design pattern.

The Proxy pattern is used when a large or expensive object cannot be represented directly in the program, typically because the object is in another process or even another system altogether.

In this exercise, a Proxy class implements the same interface as the Real class, making the Proxy class look like the Real class. Calls made on the Proxy class are passed to the Real class where the work is actually done (in this case, a munged string with the text "Real class received 'xxxx'".

The only difference in output here is one additional line for the first call showing the real class being instantiated. The subsequent calls do not show this line.

Definition at line 38 of file Proxy_Exercise.c.

References IWorkByProxy::DoWork, DynamicString_Clear(), DynamicString_Initialize(), DynamicString_Set(), GetProxyService(), and DynamicString::string.