Design Pattern Examples
Overview of object-oriented design patterns
Proxy_RealService.c
Go to the documentation of this file.
1
6
7#include <stdlib.h>
8#include <stdio.h>
9#include <string.h>
10
11#include "helpers/formatstring.h"
12
13#include "Proxy_RealService.h"
14
15//-----------------------------------------------------------------------------
16
20static bool _Real_DoWork(DynamicString* someArgument)
21{
22 bool success = false;
23
24 if (someArgument != NULL)
25 {
26 const char* prompt = "Real class received '%s'";
27 char *buffer = formatstring(prompt, someArgument->string);
28 if (buffer != NULL)
29 {
30 success = DynamicString_Set(someArgument, buffer);
31 free(buffer);
32 }
33 }
34 return success;
35}
36
45};
46
47//-----------------------------------------------------------------------------
48
49
51// GetRealService()
54{
55 return &_real_service;
56}
IWorkByProxy * GetRealService(void)
Return a pointer to the real service expressed as an IWorkByProxy service.
static bool _Real_DoWork(DynamicString *someArgument)
The real function that does all the work in the real service.
static IWorkByProxy _real_service
The real service that does all the work.
Declaration of the real service, accessed through the GetRealService() function, as used in the Proxy...
bool DynamicString_Set(DynamicString *string, const char *s)
Set the DynamicString object to the specified string, replacing whatever is in the DynamicString obje...
Definition: dynamicstring.c:73
char * formatstring(const char *format,...)
Use the given string and arguments to return a buffer containing the formatted string....
Definition: formatstring.c:15
Represents a string that can be grown dynamically.
Definition: dynamicstring.h:16
char * string
The string that can grow.
Definition: dynamicstring.h:17
Represents what can be done on the proxy object. This same interface is implemented on the real objec...