Design Pattern Examples
Overview of object-oriented design patterns
DesignPatternExamples_python.strategy.strategy_exercise Namespace Reference

Functions

def Strategy_Exercise ()
 Example of using the Strategy Pattern.
 

Variables

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

Function Documentation

◆ Strategy_Exercise()

def Strategy_Exercise ( void  )

Example of using the Strategy Pattern.

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 34 of file strategy_exercise.py.

Variable Documentation

◆ entries

list entries
Initial value:
1= [
2 # Name, age, height (in inches)
3 EntryInformation("Ronnie", 19, 84),
4 EntryInformation("Elaine", 29, 71),
5 EntryInformation("Jack", 20, 81),
6 EntryInformation("Myra", 35, 78),
7 EntryInformation("Fred", 18, 88),
8]
Represents an individual with a Name, Age, and Height.

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

Definition at line 13 of file strategy_exercise.py.