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">&lt;<a href="mailto:johnson@cs.uiuc.edu">johnson@cs.uiuc.edu</a>&gt;</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 &quot;value&quot; 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>
&quot;name&quot; and &quot;description&quot; instead of &quot;value&quot;.   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 &lt;<a href="mailto:btc@openinworld.com">btc@openinworld.com</a>&gt; wrote:<br>
&gt; (Resending since it didn&#39;t show up on the list overnight)<br>
&gt;<br>
&gt; What is the best way to implement &quot;enumerations&quot; in Smalltalk. For instance,<br>
&gt; for a UML definition of...<br>
&gt; &lt;&lt;enumeration&gt;&gt; Currency<br>
&gt;  &lt;&lt;enum&gt;&gt; USD   &#39;US dollar&#39;<br>
&gt;  &lt;&lt;enum&gt;&gt; EUR   &#39;Eueropean euro&#39;<br>
&gt;  &lt;&lt;enum&gt;&gt; AUD    &#39;Australian dollar&#39;<br>
&gt;<br>
&gt; here is my guess, consisting of 2 instance side methods and 3 class side<br>
&gt; methods...<br>
&gt; -------------------------<br>
&gt; Object subclass: #EpcimCurrency<br>
&gt;  instanceVariableNames: &#39;value&#39;<br>
&gt;  classVariableNames: &#39;&#39;<br>
&gt;  poolDictionaries: &#39;&#39;<br>
&gt;  category: &#39;IEC61970-Domain-Enumerations&#39;<br>
&gt;<br>
&gt; EpcimCurrency &gt;&gt; value: aCurrency<br>
&gt;  ( (self class) validate: aCurrency) ifTrue:<br>
&gt;      [ value := aCurrency<br>
&gt;      ].<br>
&gt;<br>
&gt; EpcimCurrency &gt;&gt; value<br>
&gt;  ^value<br>
&gt; -----------------------------------<br>
&gt;<br>
&gt; EpcimCurrency class<br>
&gt;  instanceVariableNames: &#39;enums&#39;<br>
&gt;<br>
&gt; EpcimCurrency class &gt;&gt; validate: aString<br>
&gt;  enums ifNil: [ self initialize ].<br>
&gt;  ^ enums includesKey: aString.<br>
&gt;<br>
&gt; EpcimCurrency class &gt;&gt;  enums   &quot;for displaying in pulldown menus&quot;<br>
&gt;  enums ifNil: [ self initialize ].<br>
&gt;  ^enums copy<br>
&gt;<br>
&gt; EpcimCurrency class &gt;&gt; initalize<br>
&gt;  (enums := Dictionary new)<br>
&gt;              add: &#39;USD&#39;-&gt; &#39;US dollar&#39; ;<br>
&gt;              add: &#39;EUR&#39;-&gt; &#39;European euro&#39; ;<br>
&gt;              add: &#39;AUD&#39;-&gt; &#39;Australian dollar&#39; ;<br>
&gt;              add: &#39;CAD&#39;-&gt; &#39;Canadian dollar&#39; ;<br>
&gt;              add: &#39;CHF&#39;-&gt; &#39;Swiss francs&#39; ;<br>
&gt;              add: &#39;CNY&#39;-&gt; &#39;Chinese yuan renminbi&#39; ;<br>
&gt;              add: &#39;DKK&#39;-&gt; &#39;Danish crown&#39; ;<br>
&gt;              add: &#39;GBP&#39;-&gt; &#39;British pound&#39; ;<br>
&gt;              add: &#39;JPY&#39;-&gt; &#39;Japanese yen&#39; ;<br>
&gt;              add: &#39;NOK&#39;-&gt; &#39;Norwegian crown&#39; ;<br>
&gt;              add: &#39;RUR&#39;-&gt; &#39;Russian ruble&#39; ;<br>
&gt;              add: &#39;SEK&#39;-&gt; &#39;Swedish crown&#39; ;<br>
&gt;              add: &#39;INR&#39;-&gt; &#39;India rupees&#39; ;<br>
&gt;              add: &#39;other&#39;-&gt; &#39;Another type of currency&#39; .<br>
&gt; ----------------------<br>
&gt; Examples<br>
&gt;  &quot; (EpcimCurrency new value: &#39;AUD&#39; ) value inspect  &quot;      ----&gt; &#39;AUD&#39;<br>
&gt;  &quot; (EpcimCurrency new value: &#39;XXX&#39;) value  inspect  &quot;      ----&gt; nil<br>
&gt;  &quot; EpcimCurrency initialize  &quot;<br>
&gt;  &quot; EpcimCurrency enums inspect &quot;   ---&gt; aDictionary<br>
&gt; ------<br>
&gt; The other way I thought might be like `Color blue`, but I&#39;m not sure what is<br>
&gt; gained.<br>
&gt;<br>
&gt; Your feedback would be appreciated.<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Beginners mailing list<br>
&gt; <a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>
&gt; <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>