[Newbies] enumerated values

Rob Rothwell r.j.rothwell at gmail.com
Sat Sep 27 00:37:00 UTC 2008


I know I didn't ask for this, but thanks for the explanation!  I am just
starting to think more in objects, although I still find myself trying to
push them around.  My new mantra is "ask the object to do it for me...ask
the object to do it form me..."
Fortunately, I am dealing with slightly more concrete objects in Healthcare
(patients, bills, supplies, etc...).

Take care,

Rob

On Fri, Sep 26, 2008 at 8:32 PM, Norbert Hartl <norbert at hartl.name> wrote:

> On Fri, 2008-09-26 at 17:06 -0500, Mark Volkmann wrote:
> > Is there an equivalent of Java's enumerated values (enum) in Smalltalk?
> >
> Yes and a very good one. We call it class! :))
>
> A usage pattern I see often is this one (in java):
>
> - define an Enum MyEnum with constants: one two three
> - anywhere in the code assign MyEnum.two to variable myCase
> - later build a case construct that selects a body of
>  code to execute depending on the value of myCase
> - execute the selected code (that prints something)
>
> So we would do:
>
> - define a class MyEnum and class methods for one, two, three
>  to create instances of MyEnum which are initialized differently.
>  MyEnum has a method printSomething which contains the same
>  code as in the enum example
> - anywhere in the code assign MyEnum two to myCase
> - later invoke myCase printSomething
>
> The difference between those two is that we use the builtin
> case construct that is called method lookup. And it is less
> code and better to read. And your constant is an object that
> is alive and could provide you with many more things than
> printSomething.
>
> Just ask if this isn't clean as I might think.
>
> Norbert
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080926/afbe2323/attachment.htm


More information about the Beginners mailing list