Design Pattern Examples
Overview of object-oriented design patterns
Proxy_ProxyService.c
Go to the documentation of this file.
1
5
6#include <stdlib.h>
7#include <stdio.h>
8#include "Proxy_RealService.h"
10
11//-----------------------------------------------------------------------------
12
18
19
27{
28 if (_realService == NULL)
29 {
30 printf(" --> Creating instance of real class...\n");
32 }
33
34 return _realService;
35}
36
47bool Proxy_DoWork(DynamicString* someArgument)
48{
49 bool success = false;
50
51 printf(" --> proxy class DoWork() in\n");
52 if (someArgument != NULL)
53 {
55 printf(" --> Forwarding DoWork() call to real class...\n");
56 success = service->DoWork(someArgument);
57 }
58
59 return success;
60}
61
67};
68
69//-----------------------------------------------------------------------------
70
71
73// GetProxyService()
76{
77 printf(" --> Creating instance of proxy class...\n");
78 return &proxy_service;
79}
bool Proxy_DoWork(DynamicString *someArgument)
Do some work on a dynamic string.
static IWorkByProxy * Proxy_GetRealService(void)
Helper function to retrieve the one and only instance of the real service. This hides the details of ...
static IWorkByProxy * _realService
The one and only instance of the real service associated with this proxy service instance.
IWorkByProxy * GetProxyService(void)
Obtain the proxy service.
IWorkByProxy proxy_service
The proxy service.
Declaration of the proxy service, accessed through the GetProxyService() function,...
IWorkByProxy * GetRealService(void)
Return a pointer to the real service expressed as an IWorkByProxy service.
Declaration of the real service, accessed through the GetRealService() function, as used in the Proxy...
Represents a string that can be grown dynamically.
Definition: dynamicstring.h:16
Represents what can be done on the proxy object. This same interface is implemented on the real objec...
bool(* DoWork)(DynamicString *someArgument)
Does some work on the given argument and updates the given argument.