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

Implementation of the Bridge_Exercise() function as used in the Bridge Pattern. More...

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "helpers/formatstring.h"
#include "Bridge_ILogger.h"
#include "Bridge_Exercise.h"
Include dependency graph for Bridge_Exercise.c:

Go to the source code of this file.

Functions

static void _Bridge_Exercise_Demonstrate_Logging (ILogger *logger, const char *loggerType)
 Helper function to show an example of writing to a logger.
 
void Bridge_Exercise (void)
 Example of using the Bridge Pattern.
 

Detailed Description

Implementation of the Bridge_Exercise() function as used in the Bridge Pattern.

Definition in file Bridge_Exercise.c.

Function Documentation

◆ _Bridge_Exercise_Demonstrate_Logging()

static void _Bridge_Exercise_Demonstrate_Logging ( ILogger logger,
const char *  loggerType 
)
static

Helper function to show an example of writing to a logger.

This is called for all types of loggers, showing how the ILogger interface hides the details of the underlying implementation.

Parameters
loggerAn ILogger instance to log to.
loggerTypeThe type of the underlying implementation.

Definition at line 30 of file Bridge_Exercise.c.

References ILogger::data, formatstring(), ILogger::LogError, ILogger::LogInfo, and ILogger::LogTrace.

Referenced by DesignPatternExamples_cpp::Bridge_Exercise(), and Bridge_Exercise().

◆ Bridge_Exercise()

void Bridge_Exercise ( void  )

Example of using the Bridge Pattern.

The Bridge pattern is used to allow a program to offer multiple ways to perform logging without changing how the logging is used throughout the program.

In this exercise, note how the calls into the logger are the same regardless of the logger used.

Definition at line 68 of file Bridge_Exercise.c.

References _Bridge_Exercise_Demonstrate_Logging(), CreateLogger(), DestroyLogger(), LoggerType_ToConsole, LoggerType_ToFile, and LoggerType_ToNull.