<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: The Power of Enum</title>
	<atom:link href="http://elegantcode.com/2010/05/08/the-power-of-enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/05/08/the-power-of-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-enum</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Wilian</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63767</link>
		<dc:creator>Wilian</dc:creator>
		<pubDate>Sun, 03 Apr 2011 22:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63767</guid>
		<description>very nice and helpful</description>
		<content:encoded><![CDATA[<p>very nice and helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joep Lijnen</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-63762</link>
		<dc:creator>Joep Lijnen</dc:creator>
		<pubDate>Sat, 02 Apr 2011 22:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-63762</guid>
		<description>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</description>
		<content:encoded><![CDATA[<p>I also like how the switch-snippet in Visual Studio will automatically fill in all enumeration fields when you use it; e.g. switch-[TAB]-[TAB] fruits [TAB] [ENTER]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant Code &#187; Enforce Correct Usage By Wrapping Types</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-58092</link>
		<dc:creator>Elegant Code &#187; Enforce Correct Usage By Wrapping Types</dc:creator>
		<pubDate>Sun, 11 Jul 2010 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-58092</guid>
		<description>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</description>
		<content:encoded><![CDATA[<p>[...] are achieving the same kind of valuable input constrictions that we have been able to achieve with enumerations, except we are adding more complex restrictions than a simple list of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57254</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 18 May 2010 18:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57254</guid>
		<description>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#039;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</description>
		<content:encoded><![CDATA[<p>I like enums as replacements for magic numbers, per Raymond Chen at the Old New Thing. Using ints, bools, and other basic types as function parameters is bad since you can&#8217;t tell from the source code line what the values are SEMANTICALLY. Enumeration values provide a way to document what was meant, not just pass a value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57041</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57041</guid>
		<description>Ha, just realised there was a previous page of comments and that stuff had already been covered...doh!</description>
		<content:encoded><![CDATA[<p>Ha, just realised there was a previous page of comments and that stuff had already been covered&#8230;doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Fowler</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57040</link>
		<dc:creator>Derek Fowler</dc:creator>
		<pubDate>Wed, 12 May 2010 12:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57040</guid>
		<description>First off, enumerations don&#039;t constrain your set of choices e.g. if your Fruits enum &quot;inherits from&quot; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &quot;123456&quot; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#039;d ever need to worry about these unspecified values but it&#039;s something you should be aware of.

Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</description>
		<content:encoded><![CDATA[<p>First off, enumerations don&#8217;t constrain your set of choices e.g. if your Fruits enum &#8220;inherits from&#8221; the default of int you can pass this in to your method no problem: (Fruits)123456. Similarly Enum.Parse() will also accept &#8220;123456&#8243; as a valid value for Fruits. Enumerations simply allow you to give some of the values of, in this case, int a special meaning. It depends on how the values are getting into your system as to whether you&#8217;d ever need to worry about these unspecified values but it&#8217;s something you should be aware of.</p>
<p>Secondly, I think the best solution to you first example is what Abinesh was getting at i.e. a more OO solution where you have an abstract Fruit class with an abstract Eat() method with Apple, Banana etc classes inheriting from it and implementing the Eat() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57033</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57033</guid>
		<description>&lt;a href=&quot;#comment-57032&quot; rel=&quot;nofollow&quot;&gt;@Abinesh&lt;/a&gt; 

Typo in eat method
public void eat(Fruit fruit){
fruit.print();// no dirty switch case
}</description>
		<content:encoded><![CDATA[<p><a href="#comment-57032" rel="nofollow">@Abinesh</a> </p>
<p>Typo in eat method<br />
public void eat(Fruit fruit){<br />
fruit.print();// no dirty switch case<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abinesh</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57032</link>
		<dc:creator>Abinesh</dc:creator>
		<pubDate>Tue, 11 May 2010 17:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57032</guid>
		<description>How about this???

public enum Fruit{
APPLE{
public void print(){System.out.println(&quot;i am apple&quot;);}
},
ORANGE{
public void print(){System.out.println(&quot;i am orange&quot;);}
},MANGO{
public void print(){System.out.println(&quot;i am mango&quot;);}};
public abstract void print();
}

your eat() can now become

public void eat(Fruit fruit)
{
fruit.eat();// no dirty switch case
}

This is in java.I hope kind of enum is possible in C#.</description>
		<content:encoded><![CDATA[<p>How about this???</p>
<p>public enum Fruit{<br />
APPLE{<br />
public void print(){System.out.println(&#8220;i am apple&#8221;);}<br />
},<br />
ORANGE{<br />
public void print(){System.out.println(&#8220;i am orange&#8221;);}<br />
},MANGO{<br />
public void print(){System.out.println(&#8220;i am mango&#8221;);}};<br />
public abstract void print();<br />
}</p>
<p>your eat() can now become</p>
<p>public void eat(Fruit fruit)<br />
{<br />
fruit.eat();// no dirty switch case<br />
}</p>
<p>This is in java.I hope kind of enum is possible in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-2/#comment-57024</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Tue, 11 May 2010 02:23:31 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57024</guid>
		<description>&lt;a href=&quot;#comment-57023&quot; rel=&quot;nofollow&quot;&gt;@Adil Ahmad&lt;/a&gt; 
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.

Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.

The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</description>
		<content:encoded><![CDATA[<p><a href="#comment-57023" rel="nofollow">@Adil Ahmad</a><br />
Sure, if we were doing this for a real application, we might have IFruit, and have an Apple, Orange etc class which all implemented a method Eat which had the different behavior.</p>
<p>Of course, we should not automatically jump to that pattern to solve this problem, because the solution maybe much simpler and be easily solved with a dictionary that maps the type of fruit to the message.</p>
<p>The point of this example was not to solve the problem of making the code as clean as possible, but to point out the use of an enum to improve that code as is.  Perhaps I should have used a different example though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adil Ahmad</title>
		<link>http://elegantcode.com/2010/05/08/the-power-of-enum/comment-page-1/#comment-57023</link>
		<dc:creator>Adil Ahmad</dc:creator>
		<pubDate>Tue, 11 May 2010 01:37:55 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/05/08/the-power-of-enum/#comment-57023</guid>
		<description>What is your opinion on the pattern called :
-Replace Conditional with Polymorphism which basically means,
If you have a conditional that chooses different behavior depending on the type of an object.
Move each leg of the conditional to an overriding method in a subclass. Make the original method abstract.
Do you think its applicable here.</description>
		<content:encoded><![CDATA[<p>What is your opinion on the pattern called :<br />
-Replace Conditional with Polymorphism which basically means,<br />
If you have a conditional that chooses different behavior depending on the type of an object.<br />
Move each leg of the conditional to an overriding method in a subclass. Make the original method abstract.<br />
Do you think its applicable here.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

