<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-34047625.post116157755931600138..comments</id><updated>2007-06-20T21:13:59.887-06:00</updated><title type='text'>Comments on e.zed: Switch Statement = Ghetto... Enum = Ghetto</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.ezed.ca/feeds/116157755931600138/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34047625/116157755931600138/comments/default'/><link rel='alternate' type='text/html' href='http://blog.ezed.ca/2006/10/switch-statement-ghetto-enum-ghetto.html'/><author><name>Jonas Avellana</name><uri>http://www.blogger.com/profile/15498358433180190534</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-34047625.post-3194412736572115898</id><published>2007-06-20T21:13:00.000-06:00</published><updated>2007-06-20T21:13:00.000-06:00</updated><title type='text'>Try the following code. The only problem I see wit...</title><content type='html'>Try the following code. The only problem I see with you're code is that you are implicitly creating your strategy classes in your code. Tell, Don't Ask is my motto. Make those type codes work for a living.&lt;BR/&gt;&lt;BR/&gt;Additional Classes is a cached repository for the strategies classes. and then a locater for the repository. I even included a composite strategy, ALL, cause sometimes we have too much time on our hands.&lt;BR/&gt;&lt;BR/&gt;using System.Collections;&lt;BR/&gt;using NUnit.Framework;&lt;BR/&gt;&lt;BR/&gt;namespace Ghetto&lt;BR/&gt;{&lt;BR/&gt;    [TestFixture]&lt;BR/&gt;    public class TestGhetto&lt;BR/&gt;    {&lt;BR/&gt;        private Person gutzer;&lt;BR/&gt;&lt;BR/&gt;        [SetUp]&lt;BR/&gt;        public void SetUp()&lt;BR/&gt;        {&lt;BR/&gt;            gutzer = new Person("Gutzer");&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        [TearDown]&lt;BR/&gt;        public void TearDown()&lt;BR/&gt;        {&lt;BR/&gt;            gutzer = null;&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        [Test]&lt;BR/&gt;        public void ShouldDJ()&lt;BR/&gt;        {&lt;BR/&gt;            gutzer.WhatImDoing(Doing.DJ);&lt;BR/&gt;            gutzer.DoingIt();&lt;BR/&gt;            Assert.IsTrue(gutzer.Spent);&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        [Test]&lt;BR/&gt;        public void ShouldBMX()&lt;BR/&gt;        {&lt;BR/&gt;            gutzer.WhatImDoing(Doing.BMX);&lt;BR/&gt;            gutzer.DoingIt();&lt;BR/&gt;            Assert.IsTrue(gutzer.Spent);&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        [Test]&lt;BR/&gt;        public void ShouldGetDrunk()&lt;BR/&gt;        {&lt;BR/&gt;            gutzer.WhatImDoing(Doing.DRUNK);&lt;BR/&gt;            gutzer.DoingIt();&lt;BR/&gt;            Assert.IsTrue(gutzer.Spent);&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        [Test]&lt;BR/&gt;        public void ShouldDoItAll()&lt;BR/&gt;        {&lt;BR/&gt;            gutzer.WhatImDoing(Doing.ALL);&lt;BR/&gt;            gutzer.DoingIt();&lt;BR/&gt;            Assert.IsTrue(gutzer.Spent);&lt;BR/&gt;        }&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;    public class Doing&lt;BR/&gt;    {&lt;BR/&gt;        public static Doing DJ = new Doing();&lt;BR/&gt;        public static Doing BMX = new Doing();&lt;BR/&gt;        public static Doing DRUNK = new Doing();&lt;BR/&gt;        public static Doing ALL = new Doing();&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;&lt;BR/&gt;    public class Person&lt;BR/&gt;    {&lt;BR/&gt;        private readonly string mName;&lt;BR/&gt;        private bool spent;&lt;BR/&gt;        private Doing isDoing;&lt;BR/&gt;&lt;BR/&gt;        public Person(string name)&lt;BR/&gt;        {&lt;BR/&gt;            mName = name;&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        public string Name&lt;BR/&gt;        {&lt;BR/&gt;            get { return mName; }&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        public bool Spent&lt;BR/&gt;        {&lt;BR/&gt;            get { return spent; }&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        public void DoingIt()&lt;BR/&gt;        {&lt;BR/&gt;            DoingThings things = DoingThingsLocater.GetDoingThings();&lt;BR/&gt;            spent = things.DoIt(isDoing);&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        public void WhatImDoing(Doing doing)&lt;BR/&gt;        {&lt;BR/&gt;            isDoing = doing;&lt;BR/&gt;        }&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;    public class DoingThingsLocater&lt;BR/&gt;    {&lt;BR/&gt;        public static DoingThings GetDoingThings()&lt;BR/&gt;        {&lt;BR/&gt;            return new DoingThings();&lt;BR/&gt;        }&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;    public class DoingThings&lt;BR/&gt;    {&lt;BR/&gt;        private readonly Hashtable things = new Hashtable();&lt;BR/&gt;&lt;BR/&gt;        public DoingThings()&lt;BR/&gt;        {&lt;BR/&gt;            things[Doing.BMX] = new BMXStrategy();&lt;BR/&gt;            things[Doing.DJ] = new DJStrategy();&lt;BR/&gt;            things[Doing.DRUNK] = new GetDrunkStrategy();&lt;BR/&gt;            things[Doing.ALL] = new AllStrategy(new DJStrategy(), new BMXStrategy(), new GetDrunkStrategy());&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        public bool DoIt(Doing doing)&lt;BR/&gt;        {&lt;BR/&gt;            DoingStrategy doingIt = things[doing] as DoingStrategy;&lt;BR/&gt;            if (doingIt != null) &lt;BR/&gt;                return doingIt.GettingItDone();&lt;BR/&gt;            return false;&lt;BR/&gt;        }&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;    public abstract class DoingStrategy&lt;BR/&gt;    {&lt;BR/&gt;        public abstract bool GettingItDone();&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;    public class DJStrategy : DoingStrategy&lt;BR/&gt;    {&lt;BR/&gt;        public override bool GettingItDone()&lt;BR/&gt;        {&lt;BR/&gt;            return true;&lt;BR/&gt;        }&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;    public class BMXStrategy : DoingStrategy&lt;BR/&gt;    {&lt;BR/&gt;        public override bool GettingItDone()&lt;BR/&gt;        {&lt;BR/&gt;            return true;&lt;BR/&gt;        }&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;    public class GetDrunkStrategy : DoingStrategy&lt;BR/&gt;    {&lt;BR/&gt;        public override bool GettingItDone()&lt;BR/&gt;        {&lt;BR/&gt;            return true;&lt;BR/&gt;        }&lt;BR/&gt;    }&lt;BR/&gt;&lt;BR/&gt;    public class AllStrategy : DoingStrategy&lt;BR/&gt;    {&lt;BR/&gt;        private readonly IList mStrategyCompositeList = new ArrayList();&lt;BR/&gt;&lt;BR/&gt;        public AllStrategy(DoingStrategy dj, DoingStrategy bmx, DoingStrategy drunk)&lt;BR/&gt;        {&lt;BR/&gt;            mStrategyCompositeList.Add(dj);&lt;BR/&gt;            mStrategyCompositeList.Add(bmx);&lt;BR/&gt;            mStrategyCompositeList.Add(drunk);&lt;BR/&gt;        }&lt;BR/&gt;&lt;BR/&gt;        public override bool GettingItDone()&lt;BR/&gt;        {&lt;BR/&gt;            bool result = true;&lt;BR/&gt;&lt;BR/&gt;            foreach (DoingStrategy strategy in mStrategyCompositeList)&lt;BR/&gt;            {&lt;BR/&gt;                result &amp;= strategy.GettingItDone();&lt;BR/&gt;            }&lt;BR/&gt;&lt;BR/&gt;            return result;&lt;BR/&gt;        }&lt;BR/&gt;    }&lt;BR/&gt;}</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34047625/116157755931600138/comments/default/3194412736572115898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34047625/116157755931600138/comments/default/3194412736572115898'/><link rel='alternate' type='text/html' href='http://blog.ezed.ca/2006/10/switch-statement-ghetto-enum-ghetto.html?showComment=1182395580000#c3194412736572115898' title=''/><author><name>gutzoft</name><uri>http://www.blogger.com/profile/16876581810450748074</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.ezed.ca/2006/10/switch-statement-ghetto-enum-ghetto.html' ref='tag:blogger.com,1999:blog-34047625.post-116157755931600138' source='http://www.blogger.com/feeds/34047625/posts/default/116157755931600138' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-34047625.post-116313403199537919</id><published>2006-11-09T21:47:00.000-07:00</published><updated>2006-11-09T21:47:00.000-07:00</updated><title type='text'>I have so much enum centric code. I just tried ref...</title><content type='html'>I have so much enum centric code. I just tried refactoring my code as you have shown here and it works so much better. Thank you!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/34047625/116157755931600138/comments/default/116313403199537919'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/34047625/116157755931600138/comments/default/116313403199537919'/><link rel='alternate' type='text/html' href='http://blog.ezed.ca/2006/10/switch-statement-ghetto-enum-ghetto.html?showComment=1163134020000#c116313403199537919' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.ezed.ca/2006/10/switch-statement-ghetto-enum-ghetto.html' ref='tag:blogger.com,1999:blog-34047625.post-116157755931600138' source='http://www.blogger.com/feeds/34047625/posts/default/116157755931600138' type='text/html'/></entry></feed>