SharkTooth
Programmer
Hi, I'm looking for a nice OOP pattern to handle the counter for stepping through a survey. As the user progresses through the survey decisions are made to determine what page the user sees next. I have to indicate at the top of each page what step the user in on, like: 1 of 6, 2 of 6... Since some of the answers will send the user to a different number of pages the current step will need to be adjusted. So a user may start on page 2 of 6 but because of the answers to the survey they skip step 3 of 6 and go right to 4 of 6.
I can do all of this with inline code on each page. Does anyone have a better idea on how to handle this and keep track of the steps? Is there a pattern that fits this? I thought I would use an object and pass it around in a session. This is the class I started to build.
Thanks for your thoughts.
I can do all of this with inline code on each page. Does anyone have a better idea on how to handle this and keep track of the steps? Is there a pattern that fits this? I thought I would use an object and pass it around in a session. This is the class I started to build.
Code:
public class Stepper{
int _start=0, _end=0, _current=0;
public Stepper(int start, int end, int current){
_start=start;
_end=end;
_current=current;
}
public int Start{
get{return _start;}
set{_start = value;}
}
public int End{
get{return _end;}
set{_end = value;}
}
public int Current{
get{return _current;}
set{_current = value;}
}
public void AddStepEnd(){
_end++;
}
public void SubtractStepEnd(){
_end--;
}
public void AddStepCurrent(){
_current++;
}
public void SubtractStepCurrent(){
_current--;
}
}
Thanks for your thoughts.