<?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>spiros.blog() &#187; OOP</title>
	<atom:link href="http://www.tzavellas.com/techblog/tag/oop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tzavellas.com/techblog</link>
	<description>Spiros Tzavellas’s blog, mostly on software development and Java.</description>
	<lastBuildDate>Sun, 22 Aug 2010 20:25:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>commons.testing</title>
		<link>http://www.tzavellas.com/techblog/2007/04/01/commonstesting/</link>
		<comments>http://www.tzavellas.com/techblog/2007/04/01/commonstesting/#comments</comments>
		<pubDate>Sun, 01 Apr 2007 20:33:20 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/04/01/commonstesting/</guid>
		<description><![CDATA[For me, this is the best April fool&#8217;s joke for this year.]]></description>
			<content:encoded><![CDATA[<p>For me, <a href="http://www.mockobjects.com/2007/03/announcing-commonstesting-and.html">this</a> is the best April fool&#8217;s joke for this year.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/04/01/commonstesting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gang Of Four Design Patterns Crossword</title>
		<link>http://www.tzavellas.com/techblog/2007/03/02/gang-of-four-design-patterns-crossword/</link>
		<comments>http://www.tzavellas.com/techblog/2007/03/02/gang-of-four-design-patterns-crossword/#comments</comments>
		<pubDate>Fri, 02 Mar 2007 17:27:02 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
				<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/03/02/gang-of-four-design-patterns-crossword/</guid>
		<description><![CDATA[Test your design patterns knowledge with this Javascript game. BTW I missed one pattern (via Ajaxian)]]></description>
			<content:encoded><![CDATA[<p>Test your design patterns knowledge with <a href="http://www.vokamis.com/products/cword/app/enterGame.php?ns=/a/a&#038;or=V&#038;h=128&#038;pub=2&#038;ex=http://www.softwaresecretweapons.com/jspwiki/Wiki.jsp?page=GangOfFourSoftwareDesignPatternsJavaScriptCrossword">this</a> Javascript game.</p>
<p>BTW I missed one pattern <img src='http://www.tzavellas.com/techblog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p>(via <a href="http://www.ajaxian.com">Ajaxian</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/03/02/gang-of-four-design-patterns-crossword/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A simple example of &#8220;Tell, don&#8217;t Ask&#8221;</title>
		<link>http://www.tzavellas.com/techblog/2007/02/17/a-simple-example-of-tell-dont-ask/</link>
		<comments>http://www.tzavellas.com/techblog/2007/02/17/a-simple-example-of-tell-dont-ask/#comments</comments>
		<pubDate>Fri, 16 Feb 2007 22:09:10 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/?p=62</guid>
		<description><![CDATA[The &#8220;Tell, don&#8217;t Ask&#8221; object oriented principle says: &#8230; you should endeavor to tell objects what you want them to do; do not ask them questions about their state, make a decision, and then tell them what to do. Below I have a simple example from the Google Web Toolkit APIs that demonstrates how a [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html">&#8220;Tell, don&#8217;t Ask&#8221;</a> object oriented principle says:</p>
<blockquote><p>&#8230; you should endeavor to tell objects what you want them to do; do not ask them questions about their state, make a decision, and then tell them what to do.</p></blockquote>
<p>Below I have a simple example from the<a href="http://code.google.com/webtoolkit/documentation/gwt.html"> Google Web Toolkit APIs</a> that demonstrates how a small change in the API of a class to obey this principle can make the code more clean and remove code repetition.</p>
<p>In the first version (1.0.20 if I am correct) of the <a href="http://code.google.com/webtoolkit/">GWT</a> in order to remove a <code>Widget</code> from its parent you had to write the following code:</p>
<p><strong>Ask version</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Widget w <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>w.<span style="color: #006633;">getParent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Panel</span> parent <span style="color: #339933;">=</span> w.<span style="color: #006633;">getParent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    parent.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>w<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the above code <em>we ask</em> the <code>Widget</code> object for its parent <code>Panel</code> (internal state) check that the parent is not null (make a decision based on the inner state of another object) and remove the widget from the its parent panel.</p>
<p>In the version 1.1.10 of the <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> the <code>Widget</code> class was refactored and a new <code>removeFromParent()</code> method was introduced. With this refactoring we can now write:</p>
<p><strong>Tell version</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Widget w <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span>
w.<span style="color: #006633;">removeFromParent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this version of the code we don&#8217;t care if the <code>Widget</code> object has a parent or not. We simply <em>tell</em> to the <code>Widget</code> object to remove itself from its parent and the <code>Widget</code> object knows how to deal with all the variations of its internal state. The code now in much simpler and the repetition to check if the parent is <code>null</code> is gone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/02/17/a-simple-example-of-tell-dont-ask/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thinking in Code</title>
		<link>http://www.tzavellas.com/techblog/2006/06/12/thinking-in-code/</link>
		<comments>http://www.tzavellas.com/techblog/2006/06/12/thinking-in-code/#comments</comments>
		<pubDate>Mon, 12 Jun 2006 19:26:25 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Podcast]]></category>

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/?p=54</guid>
		<description><![CDATA[Bruce Eckel has a podcast with 12 interviews of various software luminaries. All the interviews took place in 2003 but Eckel only recently released them. You can find interviews of Anders Hejlsberg, Guido Van Rossum, Joshua Bloch, Martin Fowler, Ron Jeffries and others.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mindviewinc.com/">Bruce Eckel</a> has a <a href="http://www.mindviewinc.com/mediacast/interviews/Index.php">podcast</a> with 12 interviews of various software luminaries. All the interviews took place in 2003 but Eckel only recently released them. You can find interviews of Anders Hejlsberg, Guido Van Rossum, Joshua Bloch, Martin Fowler, Ron Jeffries and others.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2006/06/12/thinking-in-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prototype based object models</title>
		<link>http://www.tzavellas.com/techblog/2005/12/06/prototype-based-object-models/</link>
		<comments>http://www.tzavellas.com/techblog/2005/12/06/prototype-based-object-models/#comments</comments>
		<pubDate>Tue, 06 Dec 2005 13:38:55 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/?p=38</guid>
		<description><![CDATA[The Mozilla Developer Center has a great guide for Javascript. This guide provides one of the best explanations I&#8217;ve read on the Javascript object model and on prototype based object models in general. Although I have only programed with languages that provide class based object models I believe that that prototype based object models are [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://developer.mozilla.org/">Mozilla Developer Center</a> has a great <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide">guide</a> for <a href="http://developer.mozilla.org/en/docs/JavaScript">Javascript</a>. This guide provides one of the best explanations I&#8217;ve read on the <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Details_of_the_Object_Model">Javascript object model</a> and on prototype based object models in general.</p>
<p>Although I have only programed with languages that provide class based object models I believe that that prototype based object models are very easy to understand if you know the primitives of object oriented programming.</p>
<p>Prototype based object models are an interesting idea that suits very well with dynamic languages like <a href="http://developer.mozilla.org/en/docs/JavaScript">Javascript</a>. The only thing that I don&#8217;t really like is the syntax. For example creating a new “class” that inherits from an Employee “class” looks like this in <a href="http://developer.mozilla.org/en/docs/JavaScript">Javascript</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Manager <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">reports</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
Manager.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Employee<span style="color: #339933;">;</span></pre></div></div>

<p>And in <a href="http://java.sun.com">Java</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Manager <span style="color: #000000; font-weight: bold;">extends</span> Employee <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> Employee<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> reports<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">public</span> Manager <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">reports</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I prefer the <a href="http://java.sun.com">Java</a> version because the whole definition is included in one syntactic unit (a class definition), instead two in <a href="http://developer.mozilla.org/en/docs/JavaScript">Javascript</a> (a function definition and an assignment).</p>
<p>If I am correct, <a href="http://www.ruby-lang.org/">Ruby</a> (BTW I don&#8217;t know <a href="http://www.ruby-lang.org/">Ruby</a> and <a href="http://developer.mozilla.org/en/docs/JavaScript">Javascript</a>) has a class based object model but also has most of the features of languages that are prototype based. For example in <a href="http://www.ruby-lang.org/">Ruby</a>, you can add or modify, at runtime, methods of classes and instances.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2005/12/06/prototype-based-object-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
