Design Pattern Examples
Overview of object-oriented design patterns
Strategy_Exercise Class Reference

Example of using the Strategy Pattern in C#. More...

Collaboration diagram for Strategy_Exercise:
Collaboration graph

Public Member Functions

void Run ()
 Executes the example for the Strategy Pattern in C#.
 

Private Attributes

EntryInformation[] entries
 List of individuals to play around with in the Strategy exercise.
 

Detailed Description

Example of using the Strategy Pattern in C#.

The Strategy pattern provides a way to easily assign different algorithms to a class instance that can be changed at the time the class is created.

In this exercise, the Strategy_ShowEntries_Class instance sorts and displays a list of EntryInformation elements. Three different sorting strategies are provided (Name, Age, Height) and an option to reverse the normal order of the sort.

Definition at line 22 of file Strategy_Exercise.cs.

Member Function Documentation

◆ Run()

void Run ( )
inline

Executes the example for the Strategy Pattern in C#.

Definition at line 41 of file Strategy_Exercise.cs.

References Strategy_Exercise.entries, and Strategy_ShowEntries_Class.ShowEntries().

Referenced by Program.Run().

Member Data Documentation

◆ entries

EntryInformation [] entries
private
Initial value:
=
{
new EntryInformation("Ronnie", 19, 84),
new EntryInformation("Elaine", 29, 71),
new EntryInformation("Jack", 20, 81),
new EntryInformation("Myra", 35, 78),
new EntryInformation("Fred", 18, 88),
}
Represents an individual with a Name, Age, and Height.

List of individuals to play around with in the Strategy exercise.

Definition at line 27 of file Strategy_Exercise.cs.

Referenced by Strategy_Exercise.Run().


The documentation for this class was generated from the following file: