<?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: Groovy 1.6 and Per-Instance Metaclass</title>
	<atom:link href="http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/feed/" rel="self" type="application/rss+xml" />
	<link>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/</link>
	<description>The Fastest Way to Launch Successful Software</description>
	<lastBuildDate>Thu, 19 Jan 2012 16:36:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Tim Yates</title>
		<link>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/#comment-9301</link>
		<dc:creator>Tim Yates</dc:creator>
		<pubDate>Thu, 26 Feb 2009 09:03:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1406#comment-9301</guid>
		<description>Ahhh cool!  Thanks for the reply!  It was the example that confused me ;-)

Keep up the Groovy posts, it&#039;s sometimes hard to work out what&#039;s new (and why it&#039;s useful) from the release notes

Thanks again!</description>
		<content:encoded><![CDATA[<p>Ahhh cool!  Thanks for the reply!  It was the example that confused me <img src='http://pathfindersoftware.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Keep up the Groovy posts, it&#8217;s sometimes hard to work out what&#8217;s new (and why it&#8217;s useful) from the release notes</p>
<p>Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guillaume Laforge</title>
		<link>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/#comment-9300</link>
		<dc:creator>Guillaume Laforge</dc:creator>
		<pubDate>Thu, 26 Feb 2009 08:54:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1406#comment-9300</guid>
		<description>Just a small remark: per-instance MetaClass already existed and worked for POGOs. The &quot;new feature&quot; is that we can now also do the same with POJOs.</description>
		<content:encoded><![CDATA[<p>Just a small remark: per-instance MetaClass already existed and worked for POGOs. The &#8220;new feature&#8221; is that we can now also do the same with POJOs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivan Moscoso</title>
		<link>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/#comment-9299</link>
		<dc:creator>Ivan Moscoso</dc:creator>
		<pubDate>Thu, 26 Feb 2009 05:38:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1406#comment-9299</guid>
		<description>Hi Tim-- not a stupid question at all!  Effectively you get the same behavior between my example and yours in pure Groovy code.  One difference I spot though is that, while the metaclass approach will still work as expected in a Java world, you can&#039;t invoke a closure the same way as a method in Java.

If, say, you were working in a mixed environment, and a Java developer needed to reference your Groovy classes, they could still reference that &#039;postProcess()&#039; as follows:

// Java code
new ReservationService().postProcess();

If using closures, this would *not* compile (the closure is not the same as a method).  Instead, you would have to invoke the closure as follows:

import groovy.lang.Closure;
/* ... */
// Java code
ReservationService r = new ReservationService();
Closure postProcessor = (Closure)r.getPostProcess();
postProcessor.call();

So the metaclass method can be changed from Groovy in the original example, and Java code can still reference it as a method.  With closures, you need to be aware of the fact that you have exposed Closures if your code is running, say, within an existing Java framework.

This might not be a huge factor if you are only running in a Groovy environment such as Grails (I use closures a lot like that anyway), but the distinction still remains.</description>
		<content:encoded><![CDATA[<p>Hi Tim&#8211; not a stupid question at all!  Effectively you get the same behavior between my example and yours in pure Groovy code.  One difference I spot though is that, while the metaclass approach will still work as expected in a Java world, you can&#8217;t invoke a closure the same way as a method in Java.</p>
<p>If, say, you were working in a mixed environment, and a Java developer needed to reference your Groovy classes, they could still reference that &#8216;postProcess()&#8217; as follows:</p>
<p>// Java code<br />
new ReservationService().postProcess();</p>
<p>If using closures, this would *not* compile (the closure is not the same as a method).  Instead, you would have to invoke the closure as follows:</p>
<p>import groovy.lang.Closure;<br />
/* &#8230; */<br />
// Java code<br />
ReservationService r = new ReservationService();<br />
Closure postProcessor = (Closure)r.getPostProcess();<br />
postProcessor.call();</p>
<p>So the metaclass method can be changed from Groovy in the original example, and Java code can still reference it as a method.  With closures, you need to be aware of the fact that you have exposed Closures if your code is running, say, within an existing Java framework.</p>
<p>This might not be a huge factor if you are only running in a Groovy environment such as Grails (I use closures a lot like that anyway), but the distinction still remains.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Yates</title>
		<link>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/#comment-9298</link>
		<dc:creator>Tim Yates</dc:creator>
		<pubDate>Wed, 25 Feb 2009 23:29:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1406#comment-9298</guid>
		<description>Sorry...that was your code... (badly formatted)...this is the closure code:

//
// Representation of an airline booking system
//
class ReservationService {
    def name
    def reserveSeat = { flightNumber -&gt;
        /* some network call.. */
        return true
    }

    def postProcess = { }
}

class Reservation {
    def bookFlight(flightNumber, service) {
        def confirm = service.reserveSeat(flightNumber)
        if (!confirm) {
            service.postProcess = {
                println &quot;Error for provider &#039;${service.name}&#039;&quot;
            }
        }
        service.postProcess()
        return confirm
    }
}

reservation = new Reservation()

delta  = new ReservationService(name: &quot;Delta&quot;)
united = new ReservationService(name: &quot;United&quot;)

assert true == reservation.bookFlight(&quot;1234&quot;, delta)
assert true == reservation.bookFlight(&quot;1234&quot;, united)

// Mock out our connection to Delta
delta.reserveSeat = { return false }

// The following prints an error, due to &#039;postProcess&#039;
assert false == reservation.bookFlight(&quot;1234&quot;, delta)</description>
		<content:encoded><![CDATA[<p>Sorry&#8230;that was your code&#8230; (badly formatted)&#8230;this is the closure code:</p>
<p>//<br />
// Representation of an airline booking system<br />
//<br />
class ReservationService {<br />
    def name<br />
    def reserveSeat = { flightNumber -&gt;<br />
        /* some network call.. */<br />
        return true<br />
    }</p>
<p>    def postProcess = { }<br />
}</p>
<p>class Reservation {<br />
    def bookFlight(flightNumber, service) {<br />
        def confirm = service.reserveSeat(flightNumber)<br />
        if (!confirm) {<br />
            service.postProcess = {<br />
                println &#8220;Error for provider &#8216;${service.name}&#8217;&#8221;<br />
            }<br />
        }<br />
        service.postProcess()<br />
        return confirm<br />
    }<br />
}</p>
<p>reservation = new Reservation()</p>
<p>delta  = new ReservationService(name: &#8220;Delta&#8221;)<br />
united = new ReservationService(name: &#8220;United&#8221;)</p>
<p>assert true == reservation.bookFlight(&#8220;1234&#8243;, delta)<br />
assert true == reservation.bookFlight(&#8220;1234&#8243;, united)</p>
<p>// Mock out our connection to Delta<br />
delta.reserveSeat = { return false }</p>
<p>// The following prints an error, due to &#8216;postProcess&#8217;<br />
assert false == reservation.bookFlight(&#8220;1234&#8243;, delta)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Yates</title>
		<link>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/#comment-9297</link>
		<dc:creator>Tim Yates</dc:creator>
		<pubDate>Wed, 25 Feb 2009 23:28:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1406#comment-9297</guid>
		<description>This is probably a stupid question, but how does this differ from using closures:


//
// Representation of an airline booking system
//
class ReservationService {
    def name
    def reserveSeat(flightNumber) {
        /* some network call.. */
        return true
    }

    def postProcess() { }
}

class Reservation {
    def bookFlight(flightNumber, service) {
        def confirm = service.reserveSeat(flightNumber)
        if (!confirm) {
            service.metaClass.postProcess = {
                println &quot;Error for provider &#039;${service.name}&#039;&quot;
            }
        }
        service.postProcess()
        return confirm
    }
}

reservation = new Reservation()

delta  = new ReservationService(name: &quot;Delta&quot;)
united = new ReservationService(name: &quot;United&quot;)

assert true == reservation.bookFlight(&quot;1234&quot;, delta)
assert true == reservation.bookFlight(&quot;1234&quot;, united)

// Mock out our connection to Delta
delta.metaClass.reserveSeat = { return false }

// The following prints an error, due to &#039;postProcess&#039;
assert false == reservation.bookFlight(&quot;1234&quot;, delta)</description>
		<content:encoded><![CDATA[<p>This is probably a stupid question, but how does this differ from using closures:</p>
<p>//<br />
// Representation of an airline booking system<br />
//<br />
class ReservationService {<br />
    def name<br />
    def reserveSeat(flightNumber) {<br />
        /* some network call.. */<br />
        return true<br />
    }</p>
<p>    def postProcess() { }<br />
}</p>
<p>class Reservation {<br />
    def bookFlight(flightNumber, service) {<br />
        def confirm = service.reserveSeat(flightNumber)<br />
        if (!confirm) {<br />
            service.metaClass.postProcess = {<br />
                println &#8220;Error for provider &#8216;${service.name}&#8217;&#8221;<br />
            }<br />
        }<br />
        service.postProcess()<br />
        return confirm<br />
    }<br />
}</p>
<p>reservation = new Reservation()</p>
<p>delta  = new ReservationService(name: &#8220;Delta&#8221;)<br />
united = new ReservationService(name: &#8220;United&#8221;)</p>
<p>assert true == reservation.bookFlight(&#8220;1234&#8243;, delta)<br />
assert true == reservation.bookFlight(&#8220;1234&#8243;, united)</p>
<p>// Mock out our connection to Delta<br />
delta.metaClass.reserveSeat = { return false }</p>
<p>// The following prints an error, due to &#8216;postProcess&#8217;<br />
assert false == reservation.bookFlight(&#8220;1234&#8243;, delta)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (User agent is rejected)
Page Caching using memcached (User agent is rejected)

Served from: pathfindersoftware.com @ 2012-02-10 01:52:00 -->
