Represents a way of displaying a list of EntryInformation objects in a particular order. The order of sorting is a strategy that can be specified when the class is instantiated. The sorting strategy can be modified with a flag indicating whether the sort is reversed from normal (in this case, descending instead of ascending). More...
#include <Strategy_ShowEntries_Class.h>
Public Member Functions | |
Strategy_ShowEntries_Class (SortOptions sortOption, bool reversedSort) | |
Constructor. | |
void | ShowEntries (const std::vector< EntryInformation > &entries) |
Display the specified entries in sorted order. The order of the sort was established when the Strategy_ShowEntries_Class was instantiated. | |
Private Attributes | |
ISortEntries::shared_ptr_t | _sortEntries |
The sorting strategy to use. | |
bool | _reversedSort |
Whether to reverse the normal order of the sort. | |
Represents a way of displaying a list of EntryInformation objects in a particular order. The order of sorting is a strategy that can be specified when the class is instantiated. The sorting strategy can be modified with a flag indicating whether the sort is reversed from normal (in this case, descending instead of ascending).
In this particular approach, a class with a specific sorting strategy is created. It can be applied to any number of lists to achieve the specified sorting behavior as the sorting behavior cannot be changed once specified.
An alternative implementation would be to pass the choice of sorting strategy to the ShowEntries() method and instantiate the sorting class there. In this way, the list is sorted and displayed using the specified sorting strategy. The advantage of this approach is only one instance of the class is needed. The disadvantage is the need for two additional parameters that must be passed in all the time with the entries to be sorted (there might be places in the program where the sorting strategy is not known or is unavailable from the user).
Definition at line 44 of file Strategy_ShowEntries_Class.h.
|
inline |
Constructor.
sortOption | A value from the SortOptions enumeration indicating the sorting strategy to use. |
reversedSort | true if the sort is to be reversed (descending); otherwise, sort in ascending order. |
Definition at line 68 of file Strategy_ShowEntries_Class.h.
References Strategy_ShowEntries_Class::_reversedSort, Strategy_ShowEntries_Class::_sortEntries, and Strategy_SortEntries_ClassFactory::Create().
|
inline |
Display the specified entries in sorted order. The order of the sort was established when the Strategy_ShowEntries_Class was instantiated.
entries | A list of EntryInformation objects to sort and display |
Definition at line 81 of file Strategy_ShowEntries_Class.h.
References Strategy_ShowEntries_Class::_reversedSort, Strategy_ShowEntries_Class::_sortEntries, entries, and Helpers::formatstring().
Referenced by DesignPatternExamples_cpp::Strategy_Exercise().
|
private |
Whether to reverse the normal order of the sort.
This is remembered here so we can use it when outputting the list.
Definition at line 58 of file Strategy_ShowEntries_Class.h.
Referenced by Strategy_ShowEntries_Class::ShowEntries(), Strategy_SortEntries_ByName::Sort(), Strategy_SortEntries_ByAge::Sort(), Strategy_SortEntries_ByHeight::Sort(), and Strategy_ShowEntries_Class::Strategy_ShowEntries_Class().
|
private |
The sorting strategy to use.
Definition at line 50 of file Strategy_ShowEntries_Class.h.
Referenced by Strategy_ShowEntries_Class::ShowEntries(), and Strategy_ShowEntries_Class::Strategy_ShowEntries_Class().