Object>>caseOf: (was Re: [Q] Enum style Object?)

Marco Paga mail at marco-paga.de
Wed Feb 19 10:58:33 UTC 2003

Hi all.
Using switch/case/many if's is in OO languages the sign that something 
is going very wrong. The Object>>caseOf: /otherwise: should get banned 
from the image. These features are aviable in Java and sometimes are the 
reason why it looks like somebody could do OOP but in fact s/he is 
writing just the old style.
You should start using polymorphism. You really should start using the 
state pattern. Perhaps you need a bit longer to apply it but after the 
first state extension you would be very happy.

If you (Eric Merritt) and others have any questions about the 
implementation I will help you.


Hannes Hirzel wrote:

>Well the "traditional style" would be to do this with a dictionary of
>symbols as keys and blocks as alues. You ask 
>(myDict at: #someSymbol) value
>(myDict at: #someSymbol) value: anObject
>But I'm not sure if this is better than the code snippet above. At least
>it is rare style.
>I didn't even know that Object>>caseOf: exists!
>In my current 'productive' 3.5alpha image there are only three senders
>of this method:
>two in MessageNode and one in MethodFinder.
>Smalltalk teachers and traditionalists out there - what do you think?

More information about the Squeak-dev mailing list