[Q] Enum style Object?
Lex Spoon
lex at cc.gatech.edu
Fri Feb 21 09:11:07 UTC 2003
Brian T Rice <water at tunes.org> wrote:
> On Tue, 18 Feb 2003, Eric Merritt wrote:
>
> > This question probably has an obvious solution but I
> > can't see it at the moment.
> >
> > For the most part my Java experience has proved to be
> > useful in aqueak (squeak is like the garden of eden
> > compared to java :) but I am having trouble getting my
> > mind around a state machine. In java I would just
> > create a state instance var thats a byte and tehn have
> > a series of static final bytes that represent each
> > state, in C/C++ I would use an enum. I can't, however,
> > for the life of me figure out how to translate this to
> > squeak. I guess maybe the states would be class vars
> > initialized in the class initializer but this seems a
> > bit strange to me. Would one of you point me in the
> > right direction?
>
> You can use symbols (for example, #stateOne #stopped #end) and compare
> them with ==, which is pretty fast and lightweight.
>
> --
Agreed. Also, you can make a class for each state. Then you can "test"
by sending a message to it that should do the right thing. That's
probably even faster than a case statement or a sequence of if
statements, but it can be a nuisance to write out all the class
definitions.
-Lex
More information about the Squeak-dev
mailing list
|