Design Pattern Examples
Overview of object-oriented design patterns
strategy_showentries_class.py
Go to the documentation of this file.
6
7from .strategy_entryinformation import EntryInformation
8from .strategy_isortentries import SortOptions
9from .strategy_sortentries_class import Strategy_SortEntries_ClassFactory
10
11
12
33
34
43 def __init__(self, sortOption : SortOptions, reversedSort : bool) -> None:
44 self._reversedSort = reversedSort
45 self._sortEntries = Strategy_SortEntries_ClassFactory.Create(sortOption, reversedSort)
46
47
54
55
56
63 def ShowEntries(self, entries : list[EntryInformation]) -> None:
64 # Make a local copy of the entries so we don't disturb the original list.
65 localEntries = entries.copy()
66 self._sortEntries.Sort(localEntries)
67
68 # This is a tabular display, making it easier to follow the sorted data.
69 print(" Sort strategy: {0} (order = {1})".format(self._sortEntries.ToString(), "Descending" if self._reversedSort else "Ascending"))
70 print(" {0:6} {1:3} {2:3}".format("Name", "Age", "Height"))
71 print(" {0:6} {1:3} {2:3}".format("------", "---", "------"))
72 for entry in localEntries:
73 print(" {0}".format(entry.ToString()))
Represents a way of displaying a list of EntryInformation objects in a particular order.
_sortEntries
The sorting strategy to use as represented by the ISortEntries interface.
None ShowEntries(self, list[EntryInformation] entries)
Display the specified entries in sorted order.