<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Class Methods</title>
	<link>http://www.klankboomklang.com/2007/10/19/class-methods/</link>
	<description>Ruby and otherwise by Patrick Farley</description>
	<pubDate>Wed, 08 Sep 2010 20:31:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>

	<item>
		<title>By: pfarley</title>
		<link>http://www.klankboomklang.com/2007/10/19/class-methods/#comment-138</link>
		<dc:creator>pfarley</dc:creator>
		<pubDate>Tue, 30 Oct 2007 04:05:27 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/10/19/class-methods/#comment-138</guid>
		<description>Hi Rick. Sorry it took a while to get back to you on this and thanks for the comment.  It's an interesting point about managing the pool through new.  I also cringe when I see GoF patterns copied verbatim into Ruby as if the "best" C++ solutions are the "best" Ruby solutions.  That said, I think encapsulation veers uncomfortably close to misleading when a method called new does not actually return something that is new.  The nice thing about "instance" or similar is that it's not promising you anything... maybe it's new, maybe it's from a pool, the only thing it suggests is that it is an instance of what you asked for.</description>
		<content:encoded><![CDATA[<p>Hi Rick. Sorry it took a while to get back to you on this and thanks for the comment.  It&#8217;s an interesting point about managing the pool through new.  I also cringe when I see GoF patterns copied verbatim into Ruby as if the &#8220;best&#8221; C++ solutions are the &#8220;best&#8221; Ruby solutions.  That said, I think encapsulation veers uncomfortably close to misleading when a method called new does not actually return something that is new.  The nice thing about &#8220;instance&#8221; or similar is that it&#8217;s not promising you anything&#8230; maybe it&#8217;s new, maybe it&#8217;s from a pool, the only thing it suggests is that it is an instance of what you asked for.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Bradley</title>
		<link>http://www.klankboomklang.com/2007/10/19/class-methods/#comment-108</link>
		<dc:creator>Rick Bradley</dc:creator>
		<pubDate>Sat, 20 Oct 2007 19:05:23 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/10/19/class-methods/#comment-108</guid>
		<description>Patrick,
Thanks for a very interesting read.

I've often wondered why Ruby programmers who feel the need to use the Singleton (or Multiton, for that matter) patterns, don't simply change Foo.new to check a pool (@@pool), and for new objects call obj = Foo.allocate, and obj.initialize(args), pushing obj into @@pool, and returning obj.

BDD-wise the behavior we want isn't usually of concern to the caller, but it is of concern to the Foo class.  It's a creation-time behavior so it is definitely in the realm of the constructor.  Unlike Java, .new is a class method rather than an operator.  Just take over .new and implement the Singleton behavior there where it belongs.

Why should client code have to call Foo.instance, e.g., and be aware of something that should be encapsulated in Foo.   If the Singleton behavior needs to change, the .new method changes (or the override is simply taken out), and no client code has to be touched.

I wonder if not taking advantage of Ruby in this way is just a too-literal reading of the popular Java implementation of GoF patterns carried along in a "Cargo Cult" manner.

Best,
Rick</description>
		<content:encoded><![CDATA[<p>Patrick,<br />
Thanks for a very interesting read.</p>
<p>I&#8217;ve often wondered why Ruby programmers who feel the need to use the Singleton (or Multiton, for that matter) patterns, don&#8217;t simply change Foo.new to check a pool (@@pool), and for new objects call obj = Foo.allocate, and obj.initialize(args), pushing obj into @@pool, and returning obj.</p>
<p>BDD-wise the behavior we want isn&#8217;t usually of concern to the caller, but it is of concern to the Foo class.  It&#8217;s a creation-time behavior so it is definitely in the realm of the constructor.  Unlike Java, .new is a class method rather than an operator.  Just take over .new and implement the Singleton behavior there where it belongs.</p>
<p>Why should client code have to call Foo.instance, e.g., and be aware of something that should be encapsulated in Foo.   If the Singleton behavior needs to change, the .new method changes (or the override is simply taken out), and no client code has to be touched.</p>
<p>I wonder if not taking advantage of Ruby in this way is just a too-literal reading of the popular Java implementation of GoF patterns carried along in a &#8220;Cargo Cult&#8221; manner.</p>
<p>Best,<br />
Rick</p>
]]></content:encoded>
	</item>
</channel>
</rss>
