From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-13T20:31:42+09:00 Subject: Re: State Pattern Implementation On Tue, 13 May 2003 14:04:33 +0200, Robert Klemme wrote: > > "Simon Strandgaard" <0bz63fz3m1qt3001@sneakemail.com> schrieb im > Newsbeitrag news:pan.2003.05.13.11.04.00.160567@sneakemail.com... >> On Tue, 13 May 2003 10:11:42 +0200, Robert Klemme wrote: >> >> > I'd like to hear what people think: is this a reasonable > implementation of >> > the state pattern? >> >> You are representing each state by a number... with the State pattern >> isn't each state supposed to be represented by a class ? > > Normally, yes. The association with a number is just for the ease of > keying the example in. OK. > My main idea was to replace the state instance by > a redefinition of instance methods. Interesting thought. So instead of having a state variable you redefine some state-transition-methods. Clever :-) Am I understanding you correct ? > Pro is, you safe an instance and a redirection; > on the con side is increased code size for the class since > you have to include code for all states. Because you don't have an explicit state variable, the state becomes implicit. Thus its hard to tell the current state.. Just a thought :-) > I'm curios to know whether anybody did this before. I might be missing > some grave disadvantage. Kind of.. not tried the same. I have done some state machines from time to time. -- Simon Strandgaard