[Cs3] Question About States and Inheritance
Mikhail Nesterenko
mikhail at cs.kent.edu
Fri Feb 28 14:02:09 EST 2014
>
>
> For this lab, Lab 7, you asked us to only show one example of an
> incorrect transition. This is simple to do since we're hard-coding
> the program and there's no user input. But if we did have user input
> and had to account for every possible transition being called for
> every possible state (that's 6 transitions and 5 states, gives me 30
> methods) what would the easiest way of coding this?
>
>
> The way I understand it, you would need to fill out methods like so:
>
>
> ProcessState* New::instance(){};
> void New::admit(Process *p){};
> void New::dispatch(Process *p){} //does nothing;
> void New::interrupt(Process *p){} //does nothing;
> void New::startWait(Process *p){} //does nothing;
> void New::endWait(Process *p){} //does nothing;
> void New::exit(Process *p){} //does nothing;
>
>
Now that you mention it, this is a perfect case for abstract function
with a default body (to be defined in the abstract class State):
// abstract class
class State{
virtual void dispatch(Process*p) = 0;
};
void State::dispatch(Process* p){}
Thanks,
--
Mikhail
More information about the cs3
mailing list