using System using System Collections Generic using System Linq using

  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
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
List<BaseTask> taskList = new List<BaseTask>();
taskList.Add(new FetchTask());
taskList.Add(new CalculateTask());
taskList.Add(new DataSubmitTask());
for (int i = 0; i < taskList.Count; i++)
{
var task = taskList.ElementAt(i);
Console.WriteLine(task.NextStep());
}
Console.ReadKey();
}
}
class BaseTask
{
public int Step;
public BaseTask()
{
Step = 0;
}
public int NextStep()
{
Console.WriteLine("method not implemented");
return 0;
}
}
class FetchTask : BaseTask
{
new public int NextStep()
{
switch (Step)
{
case 0: return Step0();
case 1: return Step1();
case 2: return Step2();
}
return 0;
}
private int Step0()
{
Console.WriteLine(" FetchTask step " + Step.ToString());
Step++;
return 0;
}
private int Step1()
{
Console.WriteLine(" FetchTask step " + Step.ToString());
Step++;
return 0;
}
private int Step2()
{
Console.WriteLine(" FetchTask step " + Step.ToString());
Step++;
return 0;
}
}
class CalculateTask : BaseTask
{
new public int NextStep()
{
switch (Step)
{
case 0: return Step0();
case 1: return Step1();
case 2: return Step2();
}
return 0;
}
private int Step0()
{
Console.WriteLine(" CalculateTask step " + Step.ToString());
Step++;
return 0;
}
private int Step1()
{
Console.WriteLine(" CalculateTask step " + Step.ToString());
Step++;
return 0;
}
private int Step2()
{
Console.WriteLine(" CalculateTask step " + Step.ToString());
Step++;
return 0;
}
}
class DataSubmitTask : BaseTask
{
new public int NextStep()
{
switch (Step)
{
case 0: return Step0();
case 1: return Step1();
case 2: return Step2();
}
return 0;
}
private int Step0()
{
Console.WriteLine(" DataSubmitTask step " + Step.ToString());
Step++;
return 0;
}
private int Step1()
{
Console.WriteLine(" DataSubmitTask step " + Step.ToString());
Step++;
return 0;
}
private int Step2()
{
Console.WriteLine(" DataSubmitTask step " + Step.ToString());
Step++;
return 0;
}
}
}