Declaration of the Strategy_Exercise() function as used in the Strategy Pattern. More...
Go to the source code of this file.
Macros | |
#define | __STRATEGY_EXERCISE_H__ |
Functions | |
void | Strategy_Exercise (void) |
Example of using the Strategy Pattern. | |
Declaration of the Strategy_Exercise() function as used in the Strategy Pattern.
Definition in file c/Strategy_Exercise.h.
#define __STRATEGY_EXERCISE_H__ |
Definition at line 9 of file c/Strategy_Exercise.h.
void Strategy_Exercise | ( | void | ) |
Example of using the Strategy Pattern.
The Strategy pattern provides a way to easily assign different algorithms to a function that can be changed at the time the function is called.
In this exercise, the Sort_Entries() is given a sorting strategy via the SortStrategy structure, which is initialized with the appropriate options based on the value from the SortOptions enumeration.
The Display_Entries() function is given the same strategy object to display the results of the sort.
Three different sorting strategies are provided (Name, Age, Height) and an option to reverse the normal order of the sort.
Definition at line 121 of file Strategy_Exercise.c.
References Display_Entries(), entries, Sort_ByAge, Sort_ByHeight, Sort_ByName, Sort_Entries(), and SortStrategy_Initialize().