<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jkx@home &#187; pattern</title>
	<atom:link href="http://www.larsen-b.com/tags/pattern/feed" rel="self" type="application/rss+xml" />
	<link>http://www.larsen-b.com</link>
	<description>Titanium Exposé</description>
	<lastBuildDate>Tue, 31 Jan 2012 23:53:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language></language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Borg with MetaClass ?</title>
		<link>http://www.larsen-b.com/Article/107.html</link>
		<comments>http://www.larsen-b.com/Article/107.html#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Singleton is one of the well known design pattern.
In python, most of us use the Borg Singleton like, which is not a true Singleton, since only the &#8217;state is shared&#8217;. In fact, you use distinct objects but they share the same __dict__.
Yesterday, i played a bit w/ python metaclass. Beside this can be really usefull [...]]]></description>
			<content:encoded><![CDATA[<p>Singleton is one of the well known design pattern.</p>
<p>In python, most of us use the <a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531">Borg</a> Singleton like, which is not a true Singleton, since only the &#8217;state is shared&#8217;. In fact, you use distinct objects but they share the same __dict__.</p>
<p>Yesterday, i played a bit w/ python metaclass. Beside this can be really usefull under certain condition, i discover that you can build a Borg with that too :)</p>
<pre class="literal-block">class Single_imp:
def __init__(cls,name,base,dict):
cls.value = 1
def __call__(cls):
return cls
def setValue(cls,value):
cls.value = value

class Single:
__metaclass__ = Single_imp

a = Single()
b = Single()
print a
print b
a.setValue(10)
print b.value</pre>
<p>and the result:</p>
<pre class="literal-block">&lt;__main__.Single_imp instance at 0x401eb96c&gt;
&lt;__main__.Single_imp instance at 0x401eb96c&gt;
10</pre>
<p>Ok .. the code looks strange.. and not a true Singleton .. but how can i build a real true in Python ?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/107.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
