<?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>Simone Carletti&#039;s Blog &#187; design patterns</title>
	<atom:link href="http://www.simonecarletti.com/blog/tags/design-patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simonecarletti.com/blog</link>
	<description>Simone Carletti&#039;s personal ramblings on programming, syndication, search engines &#38; marketing.</description>
	<lastBuildDate>Tue, 07 Feb 2012 08:48:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ruby Proxy Pattern and Dynamic Delegation with ActiveSupport BasicObject</title>
		<link>http://www.simonecarletti.com/blog/2010/05/understanding-ruby-and-rails-proxy-patter-delegation-and-basicobject/</link>
		<comments>http://www.simonecarletti.com/blog/2010/05/understanding-ruby-and-rails-proxy-patter-delegation-and-basicobject/#comments</comments>
		<pubDate>Thu, 13 May 2010 07:55:30 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[activesupport]]></category>
		<category><![CDATA[blankobject]]></category>
		<category><![CDATA[delegation]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[proxy patter]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails 3]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby 1.9]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=1042</guid>
		<description><![CDATA[An overview of the Ruby 1.9 BasicObject, including a small proxy pattern and delegation example.]]></description>
			<content:encoded><![CDATA[<div class="flash-message info target-rails">
<p>This article targets <strong>Rails 2.3</strong> and <strong>Rails 3</strong>. The information contained in this page might not apply to different versions.</p>
</div>
<p><em>This is article is part of my series Understanding Ruby and Rails. Please see the <a href="http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-reading-source-code/">table of contents</a> for the series to view the list of all posts.</em></p>
<p>If you looked into the changes in <strong>Ruby 1.9</strong>, chances are that you already noticed <code>Object</code> is no longer the class at the top of the object-hierarchy in Ruby.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby-1.8.7-p249 &gt; String.ancestors<br />
# =&gt; [String, Enumerable, Comparable, Object, Kernel]<br />
ruby-1.9.1-p378 &gt; String.ancestors<br />
# =&gt; [String, Comparable, Object, Kernel, BasicObject]</div></td></tr></tbody></table></div>
<p>Prior 1.9, every Ruby object is a child of <code>Object</code> or, from an other point of view, <code>Object</code> is the parent of every object including <code>Class</code> and <code>Modules</code>.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby-1.8.7-p249 &gt; String.ancestors<br />
# =&gt; [String, Enumerable, Comparable, Object, Kernel]<br />
ruby-1.8.7-p249 &gt; String.class<br />
# =&gt; Class<br />
ruby-1.8.7-p249 &gt; String.class.ancestors<br />
# =&gt; [Class, Module, Object, Kernel]<br />
ruby-1.8.7-p249 &gt;</div></td></tr></tbody></table></div>
<p>In Ruby 1.9 the grandpa role is played by a new special object called <code>BasicObject</code>. <code>BasicObject</code> can be considered a minimalist <code>Object</code>, an object with <a title="Class: BasicObject" href="http://ruby-doc.org/core-1.9/classes/BasicObject.html">a very few defined methods</a>.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby-1.9.1-p378 &gt; BasicObject.instance_methods<br />
&nbsp;=&gt; [:==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__]</div></td></tr></tbody></table></div>
<h2><span id="more-1042"></span>Proxy Pattern and Dynamic Delegation</h2>
<p>For the most part of Ruby code, this change won&#8217;t mean anything special. However the <code>BasicObject</code> plays a fundamental role to implement the <a title="Proxy pattern - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Proxy_pattern">proxy pattern</a> and <a title="Understanding Ruby and Rails: Delegate" href="http://www.simonecarletti.com/blog/2009/12/inside-ruby-on-rails-delegate/">dynamic delegation</a>.</p>
<p>Let me show you an example. Let&#8217;s assume you need to log all method calls made to a bank <code>Account</code> object without changing the original <code>Account</code> definition. You can create a new class to wrap the <code>Account</code> object, log any method call then forward the request to the target object.</p>
<p>Here&#8217;s a super simple bank <code>Account</code>.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class Account<br />
<br />
&nbsp; def initialize(amount)<br />
&nbsp; &nbsp; @amount = amount<br />
&nbsp; end<br />
<br />
&nbsp; def deposit(amount)<br />
&nbsp; &nbsp; @amount += amount<br />
&nbsp; end<br />
<br />
&nbsp; def withdraw(amount)<br />
&nbsp; &nbsp; @amount -= amount<br />
&nbsp; end<br />
<br />
&nbsp; def balance<br />
&nbsp; &nbsp; @amount<br />
&nbsp; end<br />
<br />
&nbsp; def inspect<br />
&nbsp; &nbsp; puts &quot;Amount: #{@amount}&quot;<br />
&nbsp; end<br />
<br />
end</div></td></tr></tbody></table></div>
<p>and here&#8217;s our <code>AccountLogger</code> class.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class AccountLogger<br />
<br />
&nbsp; def initialize(amount)<br />
&nbsp; &nbsp; @operations = []<br />
<br />
&nbsp; &nbsp; @target = Account.new(amount)<br />
&nbsp; &nbsp; @operations &lt;&lt; [:initialize, [amount]]<br />
&nbsp; end<br />
<br />
&nbsp; def method_missing(method, *args, &amp;block)<br />
&nbsp; &nbsp; @operations &lt;&lt; [method, args]<br />
&nbsp; &nbsp; @target.send(method, *args, &amp;block)<br />
&nbsp; end<br />
<br />
&nbsp; def operations<br />
&nbsp; &nbsp; @operations<br />
&nbsp; end<br />
<br />
end</div></td></tr></tbody></table></div>
<p>The <code>AccountLogger</code> is our Proxy object. It doesn&#8217;t know anything about the target object, in fact it limits itself to log method calls and forward the request to the underlying <code>@target</code> using the <a title="Module: Kernel" href="http://ruby-doc.org/core/classes/Kernel.html#M005925">method_missing</a> hook.</p>
<p>Let&#8217;s run a few operations on a new bank <code>Account</code>.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">account = AccountLogger.new(10)<br />
<br />
account.operations<br />
# =&gt; [[:initialize, [10]]]<br />
<br />
account.balance<br />
# =&gt; 10<br />
account.operations<br />
# =&gt; [[:initialize, [10]], [:balance, []]]<br />
<br />
account.deposit(20)<br />
<br />
account.balance<br />
# =&gt; 30<br />
account.operations<br />
# =&gt; [[:initialize, [10]], [:balance, []], [:deposit, [20]], [:balance, []]]</div></td></tr></tbody></table></div>
<p>So far, everything seems to work as expected. The <code>AccountLogger</code> is executing all the operations without complaining and it also logs every single operation in the internal stack.</p>
<p>But let&#8217;s try something different. Let&#8217;s print the human-readable representation of the <code>Account</code>.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">account.inspect<br />
# =&gt; Amount: 30<br />
&nbsp; &nbsp; &nbsp;&quot;#&quot;<br />
<br />
account.operations<br />
[[:initialize, [10]], [:balance, []], [:deposit, [20]], [:balance, []]]</div></td></tr></tbody></table></div>
<p>Hey, it doesn&#8217;t work! Not only it returns a messy response, it also forgot to log the call. The problem is that <code>#inspect</code> is actually defined in our <code>AccountLogger</code>.</p>
<p><code>#inspect</code> is an instance method of the <code>Object</code> class and because every object inherits from <code>Object</code>, then our <code>AccountLogger</code> responds to <code>#inspect</code>. The <code>method_missing</code> is never triggered and our proxy miserably fails to work.</p>
<p>Here we have a serious method clashing problem. Because we can&#8217;t change our <code>Account</code> implementation, we need to manually remove every method in the AccountLogger class which might conflict with the <code>Account</code> object.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class AccountLogger<br />
<br />
&nbsp; undef_method :inspect<br />
<br />
&nbsp; # ...<br />
<br />
end</div></td></tr></tbody></table></div>
<p>This is an error-prone approach, usually not applicable for libraries with a complex API.</p>
<p>Here comes the <code>BasicObject</code>. <code>BasicObject</code> actually prevents this issue by exposing a limited set of instance methods. Simply put, it copes with the problem from a different point of view: instead of taking a rich object and removing all the unnecessary methods, take a poor object and only define what you actually need.</p>
<p>At this point, we can change the <code>AccountLogger</code> to inherit from <code>BasicObject</code>.</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class AccountLogger &lt; BasicObject<br />
<br />
&nbsp; # ...<br />
<br />
end</div></td></tr></tbody></table></div>
<p>If you are looking for a real-world example, check out the <a title="Railscasts - Refactoring &amp; Dynamic Delegator" href="http://railscasts.com/episodes/212-refactoring-dynamic-delegator">Refactoring &amp; Dynamic Delegator video from Railscasts</a>.</p>
<h2>What about BasicObject in Ruby 1.8?</h2>
<p>There have been plenty of hacks and attempts to create a <code>BasicObject</code> in Ruby 1.8 with many different approaches: <a title="Blog II - The Sequel Blog - Sequel::BasicObject and ruby 1.8" href="http://sequel.heroku.com/2010/03/31/sequelbasicobject-and-ruby-18/">Sequel::BasicObject</a>, <a title="Patterns Are Not Scary: Method Missing Proxy // RailsTips by John Nunemaker" href="http://railstips.org/blog/archives/2009/08/07/patterns-are-not-scary-method-missing-proxy/">HTTParty BasicObject</a> and <a title="Class: Builder::BlankSlate" href="http://builder.rubyforge.org/classes/Builder/BlankSlate.html">Builder::BlankState</a>.</p>
<p>The latter is by far the most famous BlankObject implementation for Ruby 1.8. AFAIK it has been the real first attempt to introduce a basic object in the Ruby community and, if remember well, the Ruby 1.9 core implementation was largely inspired by the <code>Builder</code> library.</p>
<p>Recently, a <a title="Ruby 1.8 - Backport #3195: BasicObject in 1.8.8 - Ruby Issue Tracking System" href="http://redmine.ruby-lang.org/issues/show/3195">proposal</a> have been made to back-port <code>BasicObject</code> to Ruby 1.8.8. Here&#8217;s Matz comment:</p>
<blockquote><p>I see very little (virtually no) chance for the idea, that even enhance the gap between 1.8 and 1.9.</p></blockquote>
<h2>BasicObject and Rails</h2>
<p>At this point, it&#8217;s time to talk a bit about Rails. After all, this series is called understanding Ruby and Rails. As you might guess, ActiveSupport provides its own implementation of the <code>BasicObject</code> called <code>ActiveSupport::BasicObject</code>.</p>
<p>Actually, <a title="activesupport/lib/active_support/basic_object.rb at v2.3.5 from rails's rails - GitHub" href="http://github.com/rails/rails/blob/v2.3.5/activesupport/lib/active_support/basic_object.rb">in Rails 2.3.5 it doesn&#8217;t create anything new</a>. It simply returns a modified instance of <code>BasicObject</code> or <code>Builder::BlankSlate</code> depending on whether the Ruby version is 1.9 or not.</p>
<p>The library has been modified in <a title="activesupport/lib/active_support/basic_object.rb at v3.0.0.beta.3 from rails's rails - GitHub" href="http://github.com/rails/rails/blob/v3.0.0.beta.3/activesupport/lib/active_support/basic_object.rb">Rails 3</a> dropping the <code>Builder</code> dependency. That said, in Ruby 1.8.7 you can define a <code>BasicObject</code>-like object in 4 lines of code:</p>
<div class="codecolorer-container text default code-ruby" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class BasicObject<br />
&nbsp; instance_methods.each do |m|<br />
&nbsp; &nbsp; undef_method(m) if m.to_s !~ /(?:^__|^nil?$|^send$|^object_id$)/<br />
&nbsp; end<br />
end</div></td></tr></tbody></table></div>
<p>As usual, if you need to inherit from a <code>BasicObject</code> in your Rails code, use <code>ActiveSupport::BasicObject</code>. In this way you don&#8217;t have to reinvent the wheel again and you can safely rely on a cross-version implementation.</p>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2010/09/rails-3-beware-the-tap-pattern/' rel='bookmark' title='Upgrading to Rails 3: Beware of the Object#tap pattern'>Upgrading to Rails 3: Beware of the Object#tap pattern</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-benchmarking-your-scripts/' rel='bookmark' title='Understanding Ruby and Rails: Benchmarking your Ruby scripts'>Understanding Ruby and Rails: Benchmarking your Ruby scripts</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/04/inside-ruby-on-rails-serializing-ruby-objects-with-json/' rel='bookmark' title='Understanding Ruby and Rails: Serializing Ruby objects with JSON'>Understanding Ruby and Rails: Serializing Ruby objects with JSON</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2010/05/understanding-ruby-and-rails-proxy-patter-delegation-and-basicobject/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Refactoring to Design Patterns (phpDay 2009)</title>
		<link>http://www.simonecarletti.com/blog/2009/05/refactoring-to-design-patterns/</link>
		<comments>http://www.simonecarletti.com/blog/2009/05/refactoring-to-design-patterns/#comments</comments>
		<pubDate>Tue, 19 May 2009 12:15:41 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpday2009]]></category>
		<category><![CDATA[slideshare]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=335</guid>
		<description><![CDATA[The slides from my Refactoring to Design Patterns talk at phpDay 2009 are now available. ]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-351" title="phpday-it-2009" src="http://www.simonecarletti.com/blog/wp-content/uploads/2009/05/phpday-it-2009.png" alt="phpday-it-2009" width="159" height="108" />The slides from <a href="http://www.phpday.it/site/phpday-2009/calendario-conferenze/canale-developers/refactoring-to-design-patterns/">my Refactoring to Design Patterns talk</a> at phpDay 2009 are now available. The presentation is hosted on SlideShare, while the source code is available as a Git repository on GitHub. Both video and presentation are available under the <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Common Share-Alike license</a>.</p>
<p>This session can be considered a natural evolution of my previous <a href="http://www.simonecarletti.com/blog/2009/03/design-patterns-in-php/">Design Patterns in PHP</a> talk at the PHPCon: less patterns, more details, better examples!<span id="more-335"></span></p>
<div class="centered"><iframe src="http://www.slideshare.net/slideshow/embed_code/1457240" width="425" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe><br/><br/></div>
<p><a href="http://github.com/weppos/phpDay-2009/">Source Code</a></p>
<p>If you enjoyed the presentation (or even if you didn&#8217;t), please take a minute to <a href="http://joind.in/talk/view/417">review the talk</a> and leave a feedback. I&#8217;m really looking forward to reading your comments!</p>
<p>For those who missed the conference, my talk has been recorded and published on Vimeo. Unfortunately, the quality is poor, but it&#8217;is better than nothing.</p>
<div class="centered"><object width="400" height="320" data="http://www.ustream.tv/flash/video/1514297" type="application/x-shockwave-flash"><param name="id" value="otv_o_153082" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="flashvars" value="viewcount=true&amp;autoplay=false&amp;brand=embed&amp;" /><param name="src" value="http://www.ustream.tv/flash/video/1514297" /><param name="name" value="otv_e_989848" /><param name="allowfullscreen" value="true" /></object></div>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/03/design-patterns-in-php/' rel='bookmark' title='Design Patterns in PHP (PHPCon Italia)'>Design Patterns in PHP (PHPCon Italia)</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/03/book-review-design-patterns-in-ruby/' rel='bookmark' title='Design Patterns in Ruby Book Review'>Design Patterns in Ruby Book Review</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/05/refactoring-to-design-patterns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Design Patterns in PHP (PHPCon Italia)</title>
		<link>http://www.simonecarletti.com/blog/2009/03/design-patterns-in-php/</link>
		<comments>http://www.simonecarletti.com/blog/2009/03/design-patterns-in-php/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 08:52:53 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[phpcon]]></category>
		<category><![CDATA[phpcon italia]]></category>
		<category><![CDATA[slideshare]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=266</guid>
		<description><![CDATA[The slides for my talk about Design Patterns in PHP at the PHPCon Italia are now available through SlideShare.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonecarletti.com/blog/wp-content/uploads/2009/03/phpcon-logo.png"><img class="alignleft size-full wp-image-272" title="PHPCon Italia 2009 logo" src="http://www.simonecarletti.com/blog/wp-content/uploads/2009/03/phpcon-logo.png" alt="PHPCon Italia 2009 logo" width="173" height="96" /></a>The slides for my talk about <strong>Design Patterns in PHP</strong> at the <a href="http://phpcon.it/">PHPCon Italia</a> are now available through <a href="http://www.slideshare.net/weppos/design-patterns-in-php-phpcon-italia">SlideShare</a>.</p>
<p>I want to thank you everyone who came to my talk. It was really a big gratification to see such many people in the room. Unfortunately I didn&#8217;t have enough time to talk about all patterns I originally included into the presentation, however I decided to not remove them from the slides.</p>
<p>Before making the slides available, I took the time to <strong>improve the code examples</strong> replacing all the screenshots with syntax-highlighted text. This change made the code more readable and, off course, available for cut &amp; paste.<span id="more-266"></span></p>
<p>Due to the high interest in Design Patterns, I&#8217;m planning to publish some more resources in the future along with examples and implementations.</p>
<p>I do not exclude a talk or perhaps a workshop at the upcoming <a href="http://www.phpday.it/">phpDay 2009</a>. I&#8217;m thinking about a  <em>Refactoring to Patterns</em> session, with live code refactoring supported by unit tests. There is not official confirmation yet, much depends on the time I have available in the next weeks.</p>
<p>Stay tuned!</p>
<div class="centered"><iframe src="http://www.slideshare.net/slideshow/embed_code/1180261" width="425" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe><br/><br/></div>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/05/refactoring-to-design-patterns/' rel='bookmark' title='Refactoring to Design Patterns (phpDay 2009)'>Refactoring to Design Patterns (phpDay 2009)</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/03/book-review-design-patterns-in-ruby/' rel='bookmark' title='Design Patterns in Ruby Book Review'>Design Patterns in Ruby Book Review</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/03/design-patterns-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Design Patterns in Ruby Book Review</title>
		<link>http://www.simonecarletti.com/blog/2009/03/book-review-design-patterns-in-ruby/</link>
		<comments>http://www.simonecarletti.com/blog/2009/03/book-review-design-patterns-in-ruby/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 12:20:35 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[addison wesley]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[reviews]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=155</guid>
		<description><![CDATA[Design Patterns in Ruby by Russ Olsen is the first book entirely dedicated to the implementation in Ruby of the most common Design Patterns.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simonecarletti.com/blog/out/amzcom-rubypatterns"><img class="alignleft" title="Book Design Patterns in Ruby" src="http://share.weppos.net/simonecarletti/book-addison-rubypatterns-20110817-214258.png" alt="Book Design Patterns in Ruby" width="189" height="250" /></a> <a href="http://www.simonecarletti.com/blog/out/amzcom-rubypatterns"><em>Design Patterns in Ruby</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-rubypatterns">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-rubypatterns">UK</a>) is the first book entirely dedicated to the <strong>implementation of the most common Design Patterns in Ruby</strong> as defined by the <em>Gang of Four</em> (GoF). <em>Design Patterns in Ruby</em> is written by <a href="http://www.russolsen.com/">Russ Olsen</a>, edited by Addison-Wesley and is a part of the <strong>Professional Ruby Series</strong> managed by <a href="http://obiefernandez.com/">Obie Fernandez</a>. This series is without a doubt synonymous to quality and guarantee for those looking for a book on Ruby or Rails.</p>
<p>Compared to my last readings, this publication was decisively less time consuming. I finished the book in no more than a week, dedicating an hour a day in tram. On condition that you have a certain familiarity with <strong>Ruby</strong> and <strong>Object Oriented Programming</strong>, <em>Design Patterns in Ruby</em> is a quick and involving reading.<span id="more-155"></span></p>
<h2>Structure</h2>
<p>The book is divided in three parts.</p>
<p>The first part, <strong>Patterns and Ruby</strong>, is a quick introduction to the design patterns and the Ruby programming language. As I said before, you should not rely too much on the second chapter. A single section is not enough to demonstrate the power of the Ruby language.</p>
<p>The second part, <strong>Patterns in Ruby</strong>, is the heart of the book. Each chapter covers one of the different patterns originally discussed by the GoF, providing a brief introduction, practical examples of the Ruby implementation and a few real world examples, inspired by famous Ruby libraries such as <code>Rails</code> and <code>URI</code>. At the end of each chapter, a summarizing paragraph wraps up the most important Design Pattern elements.</p>
<p>The third part, <strong>Pattern for Ruby</strong>, takes into consideration three patterns not included in the original book but emerged with the introduction and the development of the Ruby language.</p>
<h3>Design Pattern discussed</h3>
<p>This is the list of all design patterns discussed in the book:</p>
<ul>
<li>Template</li>
<li>Strategy</li>
<li>Observer</li>
<li>Composite</li>
<li>Iterator</li>
<li>Commands</li>
<li>Adapter</li>
<li>Proxy</li>
<li>Decorator</li>
<li>Singleton</li>
<li>Factory</li>
<li>Builder</li>
<li>Interpreter</li>
</ul>
<p>These are the Ruby-oriented patterns covered in the third chapter:</p>
<ul>
<li>Domain-Specific Language (DSL)</li>
<li>Meta-Programming</li>
<li>Convention Over Configuration</li>
</ul>
<h2>Requirements</h2>
<p>As stated in the preface of the author, in order to read this book you don’t need to hold any particular competence either in Ruby or Design Pattern. Even so, you should have a certain familiarity with the dynamics of the object oriented programming. I confess to finding myself partially disagreeing. <strong>Tackling the reading in this book without a certain amount of knowledge of Ruby could prove itself as counter-productive</strong>, considering that some design patterns use characteristics like meta-programming, reflection, modules, symbols, Mixins, blocks, and procedures. While the previous can be considered common aspects in many languages, starting from symbols onwards, you find yourself entering in the Ruby world.</p>
<p>The second chapter of the book offers a brief introduction to Ruby, but these 30 minutes of reading are nothing compared with the experience you can learn with a day-by-day programming or a Ruby book such as the excellent <a href="http://bit.ly/cjpbLm">Learn to Program</a> or <a href="http://bit.ly/9SZ23k">Programming Ruby</a>, one of the most complete Ruby references.</p>
<p>You don’t need any specific Design Pattern knowledge in order to appreciate this book. I agree with the author in this case. It covers all Design Patterns from theory to the practical implementation providing you with a full overview of the subject.</p>
<h2>In conclusion</h2>
<p>Once more, the Addison-Wesley and the Professional Ruby Series completely met my expectations. <strong>I strongly suggest the book</strong> <a href="http://www.simonecarletti.com/blog/out/amzcom-rubypatterns"><em>Design Patterns in Ruby</em></a> (<a href="http://www.simonecarletti.com/blog/out/amzcom-rubypatterns">US</a> | <a href="http://www.simonecarletti.com/blog/out/amzuk-rubypatterns">UK</a>) to all those programmers who wish to improve their Ruby development knowledge and <strong>leverage their skills to an even more professional level</strong>. Design Patterns are an advanced and professional solution to the most common software development problems and should be part of every professional developer.</p>
<p>Russ Olsen had the ability to write an easily readable publication, without compromising the quality of the book. Each chapter is self-contained and they can be read in no specific order. If I must find a dislike, then I would say the price could be lower, compared to the average price of similar books. But you know, <strong>quality has its price</strong>.</p>
<h2>Where to Find Design Patterns in Ruby</h2>
<p>You can get a printed or Kindle copy at <a href="http://www.simonecarletti.com/blog/out/amzcom-rubypatterns">Amazon.com</a>, <a href="http://www.simonecarletti.com/blog/out/amzuk-rubypatterns">Amazon.co.uk</a>, or at your other favorite book seller.</p>
<h3>Kindle Preview</h3>
<div id="kindle-reader">.</div>
<p><script type="text/javascript" src="http://kindleweb.s3.amazonaws.com/app/KindleReader-min.js"></script><script type="text/javascript">// <![CDATA[
                         KindleReader.LoadSample({containerID: 'kindle-reader', asin: 'B0010SEN1S', width: '600', height: '629', assoctag: 'simonecarletti-20'});
// ]]&gt;</script></p>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2011/10/eloquent-ruby/' rel='bookmark' title='Eloquent Ruby Book Review'>Eloquent Ruby Book Review</a></li>
<li><a href='http://www.simonecarletti.com/blog/2010/03/book-review-learning-jquery/' rel='bookmark' title='Learning jQuery 1.3 Book Review'>Learning jQuery 1.3 Book Review</a></li>
<li><a href='http://www.simonecarletti.com/blog/2011/03/book-review-getting-real/' rel='bookmark' title='Getting Real Book Review'>Getting Real Book Review</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/03/book-review-design-patterns-in-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

