In addition, you might consider using symbols for the name rather than strings.<br><br><div class="gmail_quote">On Wed, Jan 4, 2012 at 3:33 AM, Ralph Johnson <span dir="ltr"><<a href="mailto:johnson@cs.uiuc.edu">johnson@cs.uiuc.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">That is not bad. However, EpcimCurrency needs more behavior on the<br>
instance side. In particular, a currency should know both its name<br>
and its description. i think "value" is just the name. The<br>
dictionary should map names to currencies instead of names to strings<br>
(or descriptions), and the instance should have instance variables<br>
"name" and "description" instead of "value". If you do it this way<br>
then there will only be one instance of each currency and checking for<br>
equality will be very easy. But the overall design is on target.<br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Jan 4, 2012 at 5:21 AM, Ben Coman <<a href="mailto:btc@openinworld.com">btc@openinworld.com</a>> wrote:<br>
> (Resending since it didn't show up on the list overnight)<br>
><br>
> What is the best way to implement "enumerations" in Smalltalk. For instance,<br>
> for a UML definition of...<br>
> <<enumeration>> Currency<br>
> <<enum>> USD 'US dollar'<br>
> <<enum>> EUR 'Eueropean euro'<br>
> <<enum>> AUD 'Australian dollar'<br>
><br>
> here is my guess, consisting of 2 instance side methods and 3 class side<br>
> methods...<br>
> -------------------------<br>
> Object subclass: #EpcimCurrency<br>
> instanceVariableNames: 'value'<br>
> classVariableNames: ''<br>
> poolDictionaries: ''<br>
> category: 'IEC61970-Domain-Enumerations'<br>
><br>
> EpcimCurrency >> value: aCurrency<br>
> ( (self class) validate: aCurrency) ifTrue:<br>
> [ value := aCurrency<br>
> ].<br>
><br>
> EpcimCurrency >> value<br>
> ^value<br>
> -----------------------------------<br>
><br>
> EpcimCurrency class<br>
> instanceVariableNames: 'enums'<br>
><br>
> EpcimCurrency class >> validate: aString<br>
> enums ifNil: [ self initialize ].<br>
> ^ enums includesKey: aString.<br>
><br>
> EpcimCurrency class >> enums "for displaying in pulldown menus"<br>
> enums ifNil: [ self initialize ].<br>
> ^enums copy<br>
><br>
> EpcimCurrency class >> initalize<br>
> (enums := Dictionary new)<br>
> add: 'USD'-> 'US dollar' ;<br>
> add: 'EUR'-> 'European euro' ;<br>
> add: 'AUD'-> 'Australian dollar' ;<br>
> add: 'CAD'-> 'Canadian dollar' ;<br>
> add: 'CHF'-> 'Swiss francs' ;<br>
> add: 'CNY'-> 'Chinese yuan renminbi' ;<br>
> add: 'DKK'-> 'Danish crown' ;<br>
> add: 'GBP'-> 'British pound' ;<br>
> add: 'JPY'-> 'Japanese yen' ;<br>
> add: 'NOK'-> 'Norwegian crown' ;<br>
> add: 'RUR'-> 'Russian ruble' ;<br>
> add: 'SEK'-> 'Swedish crown' ;<br>
> add: 'INR'-> 'India rupees' ;<br>
> add: 'other'-> 'Another type of currency' .<br>
> ----------------------<br>
> Examples<br>
> " (EpcimCurrency new value: 'AUD' ) value inspect " ----> 'AUD'<br>
> " (EpcimCurrency new value: 'XXX') value inspect " ----> nil<br>
> " EpcimCurrency initialize "<br>
> " EpcimCurrency enums inspect " ---> aDictionary<br>
> ------<br>
> The other way I thought might be like `Color blue`, but I'm not sure what is<br>
> gained.<br>
><br>
> Your feedback would be appreciated.<br>
><br>
><br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>
> <a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Edwin G. Castro<br><br>