<?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: Python factory-like type instances</title>
	<atom:link href="http://eikke.com/python-factory-like-type-instances/feed/" rel="self" type="application/rss+xml" />
	<link>http://eikke.com/python-factory-like-type-instances/</link>
	<description>&#039;cause this is what I do</description>
	<lastBuildDate>Wed, 10 Mar 2010 09:51:16 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Quikee</title>
		<link>http://eikke.com/python-factory-like-type-instances/comment-page-1/#comment-591</link>
		<dc:creator>Quikee</dc:creator>
		<pubDate>Mon, 11 Feb 2008 20:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://eikke.com/python-factory-like-type-instances/#comment-591</guid>
		<description>I don&#039;t know.. I prefer the below example mainly because it is without metaclass hackery (Foo magicly has some functionality but does not inherit from anything), but not quite so different:

&lt;pre&gt;import sys

class FooBase(object):
	def __new__(cls, *arguments, **keyword):
		for subclass in FooBase.__subclasses__():
			if subclass.platform == sys.platform:
				return super(cls, subclass).__new__(subclass, *arguments, **keyword)
		raise Exception, &#039;Platform not supported&#039;
	
	def say_foo(self):
		print &#039;foo&#039;

	def say_platform_foo(self):
		raise NotImplementedError

class WindowsFoo(FooBase):
	platform = &#039;win32&#039;
	
	def say_platform_foo(self):
		print &#039;win32 foo&#039;

class LinuxFoo(FooBase):
	platform = &#039;linux2&#039;
	
	def say_platform_foo(self):
		print &#039;linux foo&#039;

if __name__ == &#039;__main__&#039;:
	foo = FooBase()
	foo.say_platform_foo()
	def say_platform_foo(self):
		print &#039;linux foo&#039;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know.. I prefer the below example mainly because it is without metaclass hackery (Foo magicly has some functionality but does not inherit from anything), but not quite so different:</p>
<pre>import sys

class FooBase(object):
	def __new__(cls, *arguments, **keyword):
		for subclass in FooBase.__subclasses__():
			if subclass.platform == sys.platform:
				return super(cls, subclass).__new__(subclass, *arguments, **keyword)
		raise Exception, 'Platform not supported'

	def say_foo(self):
		print 'foo'

	def say_platform_foo(self):
		raise NotImplementedError

class WindowsFoo(FooBase):
	platform = 'win32'

	def say_platform_foo(self):
		print 'win32 foo'

class LinuxFoo(FooBase):
	platform = 'linux2'

	def say_platform_foo(self):
		print 'linux foo'

if __name__ == '__main__':
	foo = FooBase()
	foo.say_platform_foo()
	def say_platform_foo(self):
		print 'linux foo'</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
