-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathSortedList.cs
41 lines (35 loc) · 942 Bytes
/
SortedList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
namespace DoFactory.GangOfFour.Strategy.RealWorld
{
/// <summary>
/// The 'Context' class
/// </summary>
class SortedList
{
private List<string> _list = new List<string>();
private /*readonly*/ ISortStrategy _sortstrategy;
public SortedList(ISortStrategy sortStrategy)
{
_sortstrategy = sortStrategy;
}
public void SetSortStrategy(ISortStrategy sortStrategy)
{
_sortstrategy = sortStrategy;
}
public void Add(string name)
{
_list.Add(name);
}
public void Sort()
{
_sortstrategy.Sort(_list);
// Iterate over list and display results
foreach (string name in _list)
{
Console.WriteLine(" " + name);
}
Console.WriteLine();
}
}
}