pub struct StrategyShowEntries {
reversed_sort: bool,
sort_strategy: Box<dyn ISortEntries>,
}
Expand description
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 struct 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 struct with a specific sorting strategy is instantiated. The instance can be applied to any number of lists to achieve the specified sorting behavior. Note that the sorting behavior cannot be changed once the StrategyShowEntries struct is instantiated.
An alternative implementation would be to pass the choice of sorting strategy to the show_entries() method and instantiate the sorting struct there and the list is sorted and displayed using the specified sorting strategy. The advantage of this approach is that only one instance of the StrategyShowEntries struct is needed. The disadvantage is the need for two additional parameters that must be passed in all the time along 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).
Fields§
§reversed_sort: bool
Specify the sort direction (true = Ascending, false = Descending).
sort_strategy: Box<dyn ISortEntries>
The sorting strategy to use.
Implementations§
source§impl StrategyShowEntries
impl StrategyShowEntries
sourcepub fn new(sort_options: SortOptions, reversed_sort: bool) -> StrategyShowEntries
pub fn new(sort_options: SortOptions, reversed_sort: bool) -> StrategyShowEntries
Constructor.
Parameters
-
sort_option
A value from the SortOptions enumeration indicating the sorting strategy to use.
-
reversed_sort
true if to sort in descending order; otherwise, sort in ascending order.
Returns
Returns a new instance of the StrategyShowEntries struct.
sourcepub fn show_entries(&self, entries: &Vec<EntryInformation>)
pub fn show_entries(&self, entries: &Vec<EntryInformation>)
Display the specified entries in sorted order. The sorting strategy and the order of the sort were established when the StrategyShowEntries struct was instantiated.
Parameters
-
entries
The list of entries to sort and display. The original list is not changed.