G
Guest
Folks,
I am confused as to how to implement the following solution.
I have a series of processing steps, each of which contains similar features
(forms, etc). Therefore, I create a base class, Step, and subclass from that
for specific steps. The Step class has a method, Execute(), which can return
either Success or Failure.
I have a Step Driver, which instantiates the first Step, calls its Execute()
method, and then, depending on the status, runs the approriate next Step.
How do I know what the approriate next step is? I could embed this in the
Step Driver by building some data structure that can be used to decide what
to do. But this is clumsy.
In fact, each Step should "know" what the next Step for Success is, and what
the next Step for Failure is. The Execute() method, instead of returning
Success or Failure, should simply return the approriate next Step.
My initial attempt resulted, not surprisingly, in immediately using up all
available memory. Futher attmpts resulted in compiler errors.
I need some assistance in implementing the following (pseudo) code. Thanks
in advance for all suggestions!
/Joel Finkel
(e-mail address removed)
class Step : IDisposable {
string name;
Step SuccessStep; // do this is sucessful
Step NextStep; // handle failure
public Step {
}
public void ShowName() {
MessageBox.Show(name);
}
public Step Execute() {
return _execute();
}
public void Dispose() }
}
private Step _execute() {
// override for each sub class
}
}
class Step_1 : Step {
public Step_1 {
SuccessStep = Step_2; // do this is successful
FailureStep = Step_1a; // handle failure
}
private Step _execute() {
if (do some processing) {
return SuccessStep;
} else {
return FailureStep;
}
}
}
class Step_2 : Step {
public Step_2 {
SuccessStep = null; // this is the last step
FailureStep = Step_2a; // handle failure
}
private Step _execute() {
if (something) {
return SuccessStep;
} else {
return FailureStep;
}
}
}
class Step_Driver {
Step_Drvier() {
}
public void Main() {
Step nextStep;
Step thisStep = new Step_1();
// process steps until there ain't no more
while (thisStep != null) {
nextStep = thisStep.Execute();
thisStep.Dispose();
if (nextStep != null) {
thisStep = new nextStep();
}
}
}
}
I am confused as to how to implement the following solution.
I have a series of processing steps, each of which contains similar features
(forms, etc). Therefore, I create a base class, Step, and subclass from that
for specific steps. The Step class has a method, Execute(), which can return
either Success or Failure.
I have a Step Driver, which instantiates the first Step, calls its Execute()
method, and then, depending on the status, runs the approriate next Step.
How do I know what the approriate next step is? I could embed this in the
Step Driver by building some data structure that can be used to decide what
to do. But this is clumsy.
In fact, each Step should "know" what the next Step for Success is, and what
the next Step for Failure is. The Execute() method, instead of returning
Success or Failure, should simply return the approriate next Step.
My initial attempt resulted, not surprisingly, in immediately using up all
available memory. Futher attmpts resulted in compiler errors.
I need some assistance in implementing the following (pseudo) code. Thanks
in advance for all suggestions!
/Joel Finkel
(e-mail address removed)
class Step : IDisposable {
string name;
Step SuccessStep; // do this is sucessful
Step NextStep; // handle failure
public Step {
}
public void ShowName() {
MessageBox.Show(name);
}
public Step Execute() {
return _execute();
}
public void Dispose() }
}
private Step _execute() {
// override for each sub class
}
}
class Step_1 : Step {
public Step_1 {
SuccessStep = Step_2; // do this is successful
FailureStep = Step_1a; // handle failure
}
private Step _execute() {
if (do some processing) {
return SuccessStep;
} else {
return FailureStep;
}
}
}
class Step_2 : Step {
public Step_2 {
SuccessStep = null; // this is the last step
FailureStep = Step_2a; // handle failure
}
private Step _execute() {
if (something) {
return SuccessStep;
} else {
return FailureStep;
}
}
}
class Step_Driver {
Step_Drvier() {
}
public void Main() {
Step nextStep;
Step thisStep = new Step_1();
// process steps until there ain't no more
while (thisStep != null) {
nextStep = thisStep.Execute();
thisStep.Dispose();
if (nextStep != null) {
thisStep = new nextStep();
}
}
}
}