Design Pattern Examples
Overview of object-oriented design patterns
Strategy_SortStrategy.h File Reference

Declaration of the SortStrategy structure and the SortStrategy_Initialize() function as used in the Strategy Pattern. More...

#include <stdbool.h>
Include dependency graph for Strategy_SortStrategy.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  EntryInformation
 Represents an individual with a Name, Age, and Height. More...
 
struct  SortStrategy
 Represents the strategy to use for sorting EntryInformation objects. More...
 

Macros

#define __STRATEGY_SORTSTRATEGY_H__
 

Typedefs

typedef bool(* CompareFunction) (const EntryInformation *, const EntryInformation *)
 Alias for a function that compares two EntryInformation objects to determine if the left comes before the right.
 

Enumerations

enum  SortOptions { Sort_ByName = 0 , Sort_ByAge , Sort_ByHeight }
 Represents the difference sorting strategies supported. More...
 

Functions

void SortStrategy_Initialize (SortStrategy *strategy, SortOptions sortOption, bool reversedSort)
 Initialize a SortStrategy object with the desired strategy.
 

Detailed Description

Declaration of the SortStrategy structure and the SortStrategy_Initialize() function as used in the Strategy Pattern.

Definition in file Strategy_SortStrategy.h.

Macro Definition Documentation

◆ __STRATEGY_SORTSTRATEGY_H__

#define __STRATEGY_SORTSTRATEGY_H__

Definition at line 8 of file Strategy_SortStrategy.h.

Typedef Documentation

◆ CompareFunction

typedef bool(* CompareFunction) (const EntryInformation *, const EntryInformation *)

Alias for a function that compares two EntryInformation objects to determine if the left comes before the right.

Definition at line 67 of file Strategy_SortStrategy.h.

Enumeration Type Documentation

◆ SortOptions

Represents the difference sorting strategies supported.

These values are used as an index into the sortingStrategies array defined in the Strategy_SortStrategy.c file.

Enumerator
Sort_ByName 

Sort alphabetically name in ascending order.

Sort_ByAge 

Sort numerically by age in ascending order.

Sort_ByHeight 

Sort numerically by height in ascending order.

Definition at line 44 of file Strategy_SortStrategy.h.

Function Documentation

◆ SortStrategy_Initialize()

void SortStrategy_Initialize ( SortStrategy strategy,
SortOptions  sortOption,
bool  reversedSort 
)

Initialize a SortStrategy object with the desired strategy.

Parameters
strategyThe SortStrategy object to initialize.
sortOptionA value from the SortOptions enumeration specifying the sorting strategy to use.
reversedSortTrue if to reverse the sense of the compare function.

Definition at line 112 of file Strategy_SortStrategy.c.

References SortStrategyItem::compareFunction, SortStrategy::compareFunction, SortStrategyItem::name, SortStrategy::name, SortStrategy::reversedSort, and sortingStrategies.

Referenced by Strategy_Exercise().