<?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>Software development in the real world &#187; Object oriented programming</title>
	<atom:link href="http://realitydrivendeveloper.com/category/object-oriented-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://realitydrivendeveloper.com</link>
	<description></description>
	<lastBuildDate>Sat, 15 May 2010 02:44:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Memory Palace method example: Strategy pattern</title>
		<link>http://realitydrivendeveloper.com/2009/03/memory-palace-method-example-strategy-pattern/</link>
		<comments>http://realitydrivendeveloper.com/2009/03/memory-palace-method-example-strategy-pattern/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 17:41:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Object oriented programming]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[GoF]]></category>
		<category><![CDATA[memory palace]]></category>
		<category><![CDATA[mnemonics]]></category>
		<category><![CDATA[strategy pattern]]></category>

		<guid isPermaLink="false">http://realitydrivendeveloper.com/?p=47</guid>
		<description><![CDATA[This post is a sequel of previous How to start using Design Patterns post, describing the Memory Palace memorization method. I recommend you to read it before starting to read this post.
For example, I can use my sitting room as a basis for the remembering path. In this room I have the following objects:
Table, big [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a sequel of previous <a href="http://realitydrivendeveloper.com/2009/02/how-to-start-using-design-patterns/">How to start using Design Patterns</a> post, describing the Memory Palace memorization method. I recommend you to read <a href="http://realitydrivendeveloper.com/2009/02/how-to-start-using-design-patterns/">it</a> before starting to read this post.</p>
<p>For example, I can use my sitting room as a basis for the remembering path. In this room I have the following objects:<br />
Table, big bright window, lamp, sofa, picture on the wall, small bookcase, CD rack, telephone, television, DVD player, chair, mirror, black and white photographs, etc.</p>
<p>I want to put all the units required for remembering the StrategyContext implementation in that room. I&#8217;ll start from window and will move to the door out of the room.</p>
<p>When I hear the word &#8220;strategy&#8221;, the first image comes to my mind is an ancient roman warrior with armors. &#8220;Context&#8221; associates with Jacuzzi for me(something that surrounds you). So I &#8220;see&#8221; the roman warrior sitting in the Jacuzzi(pay attention at bubbles and moist air in the room).</p>
<p>Here is an example implementation of the GoF Strategy pattern, main concept of which we want to remember:<br />
I&#8217;ve taken it at <a href="http://sourcemaking.com/design_patterns/strategy/php">Strategy PHP example</a> from <a href="http://sourcemaking.com/design_patterns/">software pattern catalog</a>:<br />
<span id="more-47"></span></p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">class</span> StrategyContext <span class="br0">&#123;</span></p>
<p>private <span class="re0">$strategy</span> = <span class="kw2">NULL</span>;</p>
<p><span class="co1">//bookList is not instantiated at construct time</span></p>
<p>public <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re0">$strategy_ind_id</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p><span class="kw1">switch</span> <span class="br0">&#40;</span><span class="re0">$strategy_ind_id</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">case</span> <span class="st0">&#8220;C&#8221;</span>:<br />
<span class="re0">$this</span>-&amp;gt;strategy = <span class="kw2">new</span> StrategyCaps<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">break</span>;<br />
<span class="kw1">case</span> <span class="st0">&#8220;E&#8221;</span>:<br />
<span class="re0">$this</span>-&amp;gt;strategy = <span class="kw2">new</span> StrategyExclaim<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">break</span>;<br />
<span class="kw1">case</span> <span class="st0">&#8220;S&#8221;</span>:<br />
<span class="re0">$this</span>-&amp;gt;strategy = <span class="kw2">new</span> StrategyStars<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">break</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></p>
<p>public <span class="kw2">function</span> showBookTitle<span class="br0">&#40;</span><span class="re0">$book</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p><span class="kw1">return</span> <span class="re0">$this</span>-&amp;gt;strategy-&amp;gt;showTitle<span class="br0">&#40;</span><span class="re0">$book</span><span class="br0">&#41;</span>;</p>
<p><span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></p>
<p>interface StrategyInterface <span class="br0">&#123;</span><br />
public <span class="kw2">function</span> showTitle<span class="br0">&#40;</span><span class="re0">$book_in</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">class</span> StrategyCaps implements StrategyInterface <span class="br0">&#123;</span><br />
public <span class="kw2">function</span> showTitle<span class="br0">&#40;</span><span class="re0">$book_in</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="re0">$title</span> = <span class="re0">$book_in</span>-&amp;gt;getTitle<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="re0">$this</span>-&amp;gt;titleCount++;<br />
<span class="kw1">return</span> <a href="http://www.php.net/strtoupper"><span class="kw3">strtoupper</span></a> <span class="br0">&#40;</span><span class="re0">$title</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">class</span> StrategyExclaim implements StrategyInterface <span class="br0">&#123;</span><br />
public <span class="kw2">function</span> showTitle<span class="br0">&#40;</span><span class="re0">$book_in</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="re0">$title</span> = <span class="re0">$book_in</span>-&amp;gt;getTitle<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="re0">$this</span>-&amp;gt;titleCount++;<br />
<span class="kw1">return</span> <a href="http://www.php.net/str_replace"><span class="kw3">Str_replace</span></a><span class="br0">&#40;</span><span class="st0">&#8216; &#8216;</span>,<span class="st0">&#8216;!&#8217;</span>,<span class="re0">$title</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">class</span> StrategyStars implements StrategyInterface <span class="br0">&#123;</span><br />
public <span class="kw2">function</span> showTitle<span class="br0">&#40;</span><span class="re0">$book_in</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="re0">$title</span> = <span class="re0">$book_in</span>-&amp;gt;getTitle<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="re0">$this</span>-&amp;gt;titleCount++;<br />
<span class="kw1">return</span> <a href="http://www.php.net/str_replace"><span class="kw3">Str_replace</span></a><span class="br0">&#40;</span><span class="st0">&#8216; &#8216;</span>,<span class="st0">&#8216;*&#8217;</span>,<span class="re0">$title</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">class</span> Book <span class="br0">&#123;</span><br />
private <span class="re0">$author</span>;<br />
private <span class="re0">$title</span>;<br />
<span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re0">$title_in</span>, <span class="re0">$author_in</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="re0">$this</span>-&amp;gt;author = <span class="re0">$author_in</span>;<br />
<span class="re0">$this</span>-&amp;gt;title&nbsp; = <span class="re0">$title_in</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw2">function</span> getAuthor<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">return</span> <span class="re0">$this</span>-&amp;gt;author;<br />
<span class="br0">&#125;</span><br />
<span class="kw2">function</span> getTitle<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">return</span> <span class="re0">$this</span>-&amp;gt;title;<br />
<span class="br0">&#125;</span><br />
<span class="kw2">function</span> getAuthorAndTitle<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw1">return</span> <span class="re0">$this</span>-&amp;gt;getTitle<span class="br0">&#40;</span><span class="br0">&#41;</span> . <span class="st0">&#8216; by &#8216;</span> . <span class="re0">$this</span>-&amp;gt;getAuthor<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="re0">$book</span> = <span class="kw2">new</span> Book<span class="br0">&#40;</span><span class="st0">&#8216;PHP for Cats&#8217;</span>,<span class="st0">&#8216;Larry Truett&#8217;</span><span class="br0">&#41;</span>;</p>
<p><span class="re0">$strategyContextC</span> = <span class="kw2">new</span> StrategyContext<span class="br0">&#40;</span><span class="st0">&#8216;C&#8217;</span><span class="br0">&#41;</span>;</p>
<p><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$strategyContextC</span>-&amp;gt;showBookTitle<span class="br0">&#40;</span><span class="re0">$book</span><span class="br0">&#41;</span>;</p>
<p>?&amp;gt;</p></div>
</div>
<p>After I see the robot made from LEGO constructor, which holds the <strong>E</strong> letter in its manipulator-hand at the picture at the wall.</p>
<p>After that I see the robot&#8217;s manipulator is getting out of picture and moves the letter <strong>E</strong> to the opposite corner of the room, while the roman warrior has got out of the Jacuzzi and moved to those part of room. Manipulator gives this <strong>E</strong> letter, and while it falls down to the warrior&#8217;s hands it transforms into the exclamation mark(assign the strategy property an StrategyExclamation implementation &#8211; $this-&gt;strategy = new StrategyExclaim())</p>
<p>Now let&#8217;s move to particular StrategyExclaim implementation:</p>
<p>I&#8217;ll use the kitchen for that class. I see the warrior standing near the table, holding the knife. He wants to cut the tasty cake in form of exclamation mark, lying on the table(StrategyExclaim).</p>
<p>Near the sink I the the ostsilograf with right sine function on them. At the end of room, I see the black &#8220;magic&#8221; curtains, like those in circus. And after that I see the top of the curtains lowering(опускаются), until we can see the book&#8217;s, standing behind the curtains, top part  with its title(function showTitle($book));</p>
<p>Now, If I&#8217;ll walk this path I&#8217;ll can remind this pattern implementation. It is important, to now only remember every line of implementation, but more of core concepts(main parts), which will help you to remind the implementation.</p>
<p>Because remembering the source code is not a linear information, you&#8217;ll have to be creative and find the way of grouping the concepts and make a cross connections between them.</p>
<p>It is strongly recommended for you, to make your own &#8220;story&#8221;, because your own feelings and imagination images means much more to you, than other peoples perception, hence are remembered faster and stronger.</p>
<p>Our main purpose is not just in fast remembering the pattern, but in stay it with us for a quite long period of time. After first learning I reminisce the remembered information in my imagination, without looking at the paper or laptop</p>
<p>1) after 15 minutes</p>
<p>2) after an hour</p>
<p>3) after about 6 hours</p>
<p>4) on the next day</p>
<p>5) .. week</p>
<p>After that, if you want this information to stay in your <a href="http://en.wikipedia.org/wiki/Long-term_memory">long-term memory</a> all you have to do is to reminisce this information on a monthly basis. It will be enough.</p>
<p>I&#8217;m using the technique to memorizing different types of information: UNIX shell commands, foreign language words, framework constructs, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://realitydrivendeveloper.com/2009/03/memory-palace-method-example-strategy-pattern/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to start using Design Patterns</title>
		<link>http://realitydrivendeveloper.com/2009/02/how-to-start-using-design-patterns/</link>
		<comments>http://realitydrivendeveloper.com/2009/02/how-to-start-using-design-patterns/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 06:58:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Object oriented programming]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[ood]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://realitydrivendeveloper.com/?p=67</guid>
		<description><![CDATA[I remember myself procrastinating in using of Design Pattern in production code, after reading the information about the GoF patterns.
On the paper everything looked very easy and understandable. But after you might fall in trap of fear of using this knowledge in production code, because:

You have a very limited time dedicated for the task. So [...]]]></description>
			<content:encoded><![CDATA[<p>I remember myself procrastinating in using of <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)">Design Pattern</a> in production code, after reading the information about the <a href="http://en.wikipedia.org/wiki/Gang_of_Four">GoF</a> patterns.</p>
<p>On the paper everything looked very easy and understandable. But after you might fall in trap of fear of using this knowledge in production code, because:</p>
<ul>
<li>You have a very limited time dedicated for the task. So you can&#8217;t find the time to do the things &#8220;in right way&#8221;</li>
<li>You haven&#8217;t enough experience of some particular Design pattern, so you don&#8217;t know how to exactly implement in real problem solving. So you spend more time and get out of time scope for task and schedule. So you decide to refuse &#8220;the hard right way&#8221;, and implement an easy and dirty &#8220;temporary&#8221; solution.</li>
</ul>
<p>If you refused to implement the pattern, you haven&#8217;t improve your experience with this pattern. It is an infinity loop: you can&#8217;t implement because you don&#8217;t have a required experience. Time passes, and you will have the exact same problem in future, and the initial conditions(level of experience with particular pattern) are still low.</p>
<p>I was in this loop for a couple months. And after I recognised this behaviour habit, I&#8217;ve asked for help more my more experienced co-workers. The advice was simple and easy:</p>
<p>You can&#8217;t succeed without failure. If you want to become more experienced in Object Oriented design and Design patterns, you have to have a will in this trend, and still moving nonetheless the periodic temporary failures.</p>
]]></content:encoded>
			<wfw:commentRss>http://realitydrivendeveloper.com/2009/02/how-to-start-using-design-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
