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

Implementation of the proxy service, accessed through the GetProxyService() function, as used in the Proxy Pattern. More...

#include <stdlib.h>
#include <stdio.h>
#include "Proxy_RealService.h"
#include "Proxy_ProxyService.h"
Include dependency graph for Proxy_ProxyService.c:

Go to the source code of this file.

Functions

static IWorkByProxyProxy_GetRealService (void)
 Helper function to retrieve the one and only instance of the real service. This hides the details of instantiating the real service.
 
bool Proxy_DoWork (DynamicString *someArgument)
 Do some work on a dynamic string.
 
IWorkByProxyGetProxyService (void)
 Obtain the proxy service.
 

Variables

static IWorkByProxy_realService = NULL
 The one and only instance of the real service associated with this proxy service instance.
 
IWorkByProxy proxy_service
 The proxy service.
 

Detailed Description

Implementation of the proxy service, accessed through the GetProxyService() function, as used in the Proxy Pattern.

Definition in file Proxy_ProxyService.c.

Function Documentation

◆ GetProxyService()

IWorkByProxy * GetProxyService ( void  )

Obtain the proxy service.

Note that the real service will not be obtained until the first call into the proxy service.

Returns
Returns an IWorkByProxy object representing the proxy service.

Definition at line 75 of file Proxy_ProxyService.c.

References proxy_service.

Referenced by Proxy_Exercise().

◆ Proxy_DoWork()

bool Proxy_DoWork ( DynamicString someArgument)

Do some work on a dynamic string.

Parameters
someArgumentA DynamicString object to alter.

The real service this proxy represents is not instantiated until this function is called, even though the proxy service has been obtained. When this function is called for the first time, /// the real service is obtained, incurring a performance penalty only on the first call.

Definition at line 47 of file Proxy_ProxyService.c.

References IWorkByProxy::DoWork, and Proxy_GetRealService().

◆ Proxy_GetRealService()

static IWorkByProxy * Proxy_GetRealService ( void  )
static

Helper function to retrieve the one and only instance of the real service. This hides the details of instantiating the real service.

Returns
A single instance of the real service represented by the IWorkByProxy interface.

Definition at line 26 of file Proxy_ProxyService.c.

References _realService, and GetRealService().

Referenced by Proxy_DoWork().

Variable Documentation

◆ _realService

IWorkByProxy* _realService = NULL
static

The one and only instance of the real service associated with this proxy service instance.

Definition at line 17 of file Proxy_ProxyService.c.

Referenced by Proxy_GetRealService().

◆ proxy_service

IWorkByProxy proxy_service
Initial value:
= {
}
bool Proxy_DoWork(DynamicString *someArgument)
Do some work on a dynamic string.

The proxy service.

Definition at line 65 of file Proxy_ProxyService.c.

Referenced by GetProxyService().