<?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: Six GoF design patterns, Python style</title>
	<atom:link href="http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/feed/" rel="self" type="application/rss+xml" />
	<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/</link>
	<description>Random scribbling about programming, translation, and Japan</description>
	<lastBuildDate>Thu, 10 May 2012 05:41:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Max Guernsey, III</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-89858</link>
		<dc:creator>Max Guernsey, III</dc:creator>
		<pubDate>Tue, 12 Jul 2011 19:06:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-89858</guid>
		<description>Your decorator example is not a decorator pattern.  Decorator patterns encapsulate variations in behavior over time by allowing you to dynamically add and/or remove them (usually add).  I think if you switched to a lambda, you&#039;d be okay calling that a decorator.

Also the iterator pattern example doesn&#039;t do a lot for me.  Why not show how to make a newly iterable thing - which is the interesting part - rather than iterate over something like an array or a dictionary - which is the part most people could probably have guessed for themselves.

The other four are concise, informative, and correct.</description>
		<content:encoded><![CDATA[<p>Your decorator example is not a decorator pattern.  Decorator patterns encapsulate variations in behavior over time by allowing you to dynamically add and/or remove them (usually add).  I think if you switched to a lambda, you&#8217;d be okay calling that a decorator.</p>
<p>Also the iterator pattern example doesn&#8217;t do a lot for me.  Why not show how to make a newly iterable thing &#8211; which is the interesting part &#8211; rather than iterate over something like an array or a dictionary &#8211; which is the part most people could probably have guessed for themselves.</p>
<p>The other four are concise, informative, and correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spinner</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-35327</link>
		<dc:creator>Spinner</dc:creator>
		<pubDate>Thu, 11 Nov 2010 23:22:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-35327</guid>
		<description>How about this for Python style State Pattern
&lt;pre lang=&quot;python&quot;&gt;import EasyStatePattern as esp
class StateContext( esp.ContextBase):

	ttable = esp.TransitionTable(&#039;myState&#039;)

	def __init__(self):
		StateContext.ttable.initialize(self)

	@esp.transitionevent(ttable)
	def writeName(self, name):
		pass

class StateA(StateContext):

	def writeName(self, name):
		print name.lower()

class StateB(StateContext):

	def writeName(self, name):
		print name.upper()

class StateC(StateB):
	pass

# Set up transition table to cause states totoggle
StateContext.ttable.nextStates(StateA, (StateB,))
StateContext.ttable.nextStates(StateB, (StateC,))
StateContext.ttable.nextStates(StateC, (StateA,))
StateContext.ttable.initialstate = StateA


if __name__==&#039;__main__&#039;:
   ctxt = StateContext()
   ctxt.writeName(&quot;Monday&quot;)
   ctxt.writeName(&quot;Tuesday&quot;)
   ctxt.writeName(&quot;Wednesday&quot;)
   ctxt.writeName(&quot;Thursday&quot;)
   ctxt.writeName(&quot;Friday&quot;)
   ctxt.writeName(&quot;Saturday&quot;)
   ctxt.writeName(&quot;Sunday&quot;)
   x = raw_input(&quot;done&gt;&quot;)&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>How about this for Python style State Pattern</p>
<pre lang="python">import EasyStatePattern as esp
class StateContext( esp.ContextBase):

	ttable = esp.TransitionTable('myState')

	def __init__(self):
		StateContext.ttable.initialize(self)

	@esp.transitionevent(ttable)
	def writeName(self, name):
		pass

class StateA(StateContext):

	def writeName(self, name):
		print name.lower()

class StateB(StateContext):

	def writeName(self, name):
		print name.upper()

class StateC(StateB):
	pass

# Set up transition table to cause states totoggle
StateContext.ttable.nextStates(StateA, (StateB,))
StateContext.ttable.nextStates(StateB, (StateC,))
StateContext.ttable.nextStates(StateC, (StateA,))
StateContext.ttable.initialstate = StateA

if __name__=='__main__':
   ctxt = StateContext()
   ctxt.writeName("Monday")
   ctxt.writeName("Tuesday")
   ctxt.writeName("Wednesday")
   ctxt.writeName("Thursday")
   ctxt.writeName("Friday")
   ctxt.writeName("Saturday")
   ctxt.writeName("Sunday")
   x = raw_input("done&gt;")</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Ginstrom</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-71</link>
		<dc:creator>Ryan Ginstrom</dc:creator>
		<pubDate>Tue, 17 Mar 2009 02:41:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-71</guid>
		<description>@Stu

That&#039;s a good point. Metaclasses are certainly very powerful, but they&#039;re also complex and harder.</description>
		<content:encoded><![CDATA[<p>@Stu</p>
<p>That&#8217;s a good point. Metaclasses are certainly very powerful, but they&#8217;re also complex and harder.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stu</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-70</link>
		<dc:creator>Stu</dc:creator>
		<pubDate>Mon, 16 Mar 2009 18:14:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-70</guid>
		<description>I wonder if the factory stuff is worth doing with metaclasses (I&#039;m new to metaclasses, so might be talking rubbish).</description>
		<content:encoded><![CDATA[<p>I wonder if the factory stuff is worth doing with metaclasses (I&#8217;m new to metaclasses, so might be talking rubbish).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: -= Linkage: 2007.10.11 =-</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-69</link>
		<dc:creator>-= Linkage: 2007.10.11 =-</dc:creator>
		<pubDate>Mon, 26 Jan 2009 15:43:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-69</guid>
		<description>[...] PyGoF&lt;br/&gt; [...]</description>
		<content:encoded><![CDATA[<p>[...] PyGoF&lt;br/&gt; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tech Messages &#124; 2008-07-02 &#124; Slaptijack</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-67</link>
		<dc:creator>Tech Messages &#124; 2008-07-02 &#124; Slaptijack</dc:creator>
		<pubDate>Fri, 25 Jul 2008 06:56:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-67</guid>
		<description>[...] The GITS Blog &#187; Six GoF design patterns, Python styleDesign patterns in Python. [...]</description>
		<content:encoded><![CDATA[<p>[...] The GITS Blog &raquo; Six GoF design patterns, Python styleDesign patterns in Python. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-68</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Fri, 11 Jul 2008 21:15:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-68</guid>
		<description>Thanks a bunch for this.</description>
		<content:encoded><![CDATA[<p>Thanks a bunch for this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lvs</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-66</link>
		<dc:creator>lvs</dc:creator>
		<pubDate>Wed, 17 Oct 2007 01:46:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-66</guid>
		<description>THX
very good article</description>
		<content:encoded><![CDATA[<p>THX<br />
very good article</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Ginstrom</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-65</link>
		<dc:creator>Ryan Ginstrom</dc:creator>
		<pubDate>Tue, 09 Oct 2007 23:29:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-65</guid>
		<description>@David

You&#039;re right that the abstract factory is a bit off. I think that in a &quot;pure&quot; version, I&#039;d return a DogFactory or a CatFactory, then in the PetShop class, do
pet = self.pet_factory.get_pet()
food = self.pet_factory.get_food()
...

However, all I needed was a pet, and not a family of classes, so I fudged. But I can see how that would confuse the issue, so I&#039;ve edited the code to show the &quot;pure&quot; pattern. What do you think?</description>
		<content:encoded><![CDATA[<p>@David</p>
<p>You&#8217;re right that the abstract factory is a bit off. I think that in a &#8220;pure&#8221; version, I&#8217;d return a DogFactory or a CatFactory, then in the PetShop class, do<br />
pet = self.pet_factory.get_pet()<br />
food = self.pet_factory.get_food()<br />
&#8230;</p>
<p>However, all I needed was a pet, and not a family of classes, so I fudged. But I can see how that would confuse the issue, so I&#8217;ve edited the code to show the &#8220;pure&#8221; pattern. What do you think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Ginstrom</title>
		<link>http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/comment-page-1/#comment-64</link>
		<dc:creator>Ryan Ginstrom</dc:creator>
		<pubDate>Tue, 09 Oct 2007 23:27:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/#comment-64</guid>
		<description>&quot;In the factory example did the parrot input gave an error in the Japanese translation and thus it was only echoed?&quot;

The idea was to fail gracefully. Failure to find a translation shouldn&#039;t crash your program. And instead of checking for the msgid in the dictionary, it assumes it&#039;s there, then deals with the error if it&#039;s not (BTAFTP)...

The reason I did Unicode was that in real life(TM), I&#039;d imagine the translation dictionary stored on disk in utf-8, then have the strings converted to Unicode for display on screen.</description>
		<content:encoded><![CDATA[<p>&#8220;In the factory example did the parrot input gave an error in the Japanese translation and thus it was only echoed?&#8221;</p>
<p>The idea was to fail gracefully. Failure to find a translation shouldn&#8217;t crash your program. And instead of checking for the msgid in the dictionary, it assumes it&#8217;s there, then deals with the error if it&#8217;s not (BTAFTP)&#8230;</p>
<p>The reason I did Unicode was that in real life(TM), I&#8217;d imagine the translation dictionary stored on disk in utf-8, then have the strings converted to Unicode for display on screen.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

