<?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>Programmer&#039;s Notes &#187; efficiency</title>
	<atom:link href="http://programmersnotes.info/tag/efficiency/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmersnotes.info</link>
	<description>Notes on the web-development and artificial intelligence.</description>
	<lastBuildDate>Thu, 25 Mar 2010 08:45:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>8 Firefox plugins I use every day</title>
		<link>http://programmersnotes.info/2010/03/16/8-firefox-plugins-i-use-every-day/</link>
		<comments>http://programmersnotes.info/2010/03/16/8-firefox-plugins-i-use-every-day/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 06:00:39 +0000</pubDate>
		<dc:creator>Konstantin Mirin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://programmersnotes.info/?p=325</guid>
		<description><![CDATA[Firefox is great for web development mainly because of the large number of plug-ins available. Here&#8217;s my list:

Web developer toolbar &#8211; great thing for the web development. Personally I use resizing features, password revealing and elements highlighting.
Firebug &#8211; absolute winner. This is actually the main tool for development I use. I&#8217;m going to write a [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Firefox is great for web development mainly because of the large number of plug-ins available. Here&#8217;s my list:</p>
<ol>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/60">Web developer toolbar</a> &#8211; great thing for the web development. Personally I use resizing features, password revealing and elements highlighting.</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a> &#8211; absolute winner. This is actually the main tool for development I use. I&#8217;m going to write a more detailed post about it later. For now, you can enjoy <a href=" http://www.youtube.com/watch?v=r6F-D61S-h4">this video</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/1881">Cache status</a> shows cached size in the status bar. But the main use is it&#8217;s ability to clear cache in a few clicks. This saves lots of time clicking here and there when developing complex JS application.</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/3829">Live HTTP Headers</a> allows to view all HTTP headers that go here and there while you&#8217;re requesting the page. It&#8217;s a great thing when you need to <a href="http://programmersnotes.info/2009/05/24/grabbing-password-protected-content-with-curl/">grab some content from the password-protected area</a> or inspect what&#8217;s going on when you request page.</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/5369">YSlow</a> is a firebug plug-in from the Yahoo team which analyzes your content and shows you the ways of the client-size optimization of your page. It&#8217;s recommendations are really valuable. Try it and you&#8217;ll never uninstall it <img src='http://programmersnotes.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/12134">SitePoint HTML reference</a> is a firebug plug-in too, that adds HTML help to the every HTML tag and CSS property. It also provides examples and best practices. I don&#8217;t think this is great value for gurus, but definitely useful for all others <img src='http://programmersnotes.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/12878">Fasterfox</a> is a plug-in that boost Firefox performance. It is in the &#8220;experimental&#8221; state, but quite stable. I haven&#8217;t ever experience any problems with it.</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/2079">Selenium IDE</a> is designed as a helper tool for creating selenium tests. It is really great and handy tool if you use automated testing. I&#8217;m going to cover this in my blog later.</li>
</ol>
<p>And what are your favourite plug-ins? How do you use them?</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d325').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Liked the post? Bookmark it</em></strong></a>
<br />
<div class="d325" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F&amp;title=8+Firefox+plugins+I+use+every+day" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F&amp;title=8+Firefox+plugins+I+use+every+day" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F&amp;title=8+Firefox+plugins+I+use+every+day" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F&amp;T=8+Firefox+plugins+I+use+every+day" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F&amp;title=8+Firefox+plugins+I+use+every+day" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F&amp;title=8+Firefox+plugins+I+use+every+day" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+8+Firefox+plugins+I+use+every+day+@+http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fprogrammersnotes.info%2F2010%2F03%2F16%2F8-firefox-plugins-i-use-every-day%2F&amp;t=8+Firefox+plugins+I+use+every+day" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d325').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d325').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://programmersnotes.info/2010/03/16/8-firefox-plugins-i-use-every-day/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building high-loaded portal &#8211; InnoDB vs MyISAM</title>
		<link>http://programmersnotes.info/2009/05/20/building-high-loaded-portal-innodb-vs-myisam/</link>
		<comments>http://programmersnotes.info/2009/05/20/building-high-loaded-portal-innodb-vs-myisam/#comments</comments>
		<pubDate>Wed, 20 May 2009 07:00:55 +0000</pubDate>
		<dc:creator>Konstantin Mirin</dc:creator>
				<category><![CDATA[DB Design]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[production]]></category>

		<guid isPermaLink="false">http://konstantin.takeforce.net/?p=5</guid>
		<description><![CDATA[Post shares practical experience of developing MySQL DB for the high-loaded website.


Related posts:<ol><li><a href='http://programmersnotes.info/2009/10/06/low-coupling-and-high-cohesion-grasp-design-patterns/' rel='bookmark' title='Permanent Link: Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)'>Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)</a> <small>Low coupling When designing some architecture, you face with the...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<h2><a name="intro">Preface</a></h2>
<p>In November 2008 I&#8217;ve got a nice project, that resulted in a complex search engine, that specializes in clothing. I can&#8217;t give the link now, but will do when site officially launches. Key features of such service are:</p>
<ul>
<li>Large number of users, which search with various parameters, rate items, leave comments, create articles etc.</li>
<li>Large database, that is updated frequently</li>
</ul>
<p>Sure, the site is running on a dedicated server, sure I use caching, but optimal DB is a key to success.</p>
<p><span id="more-5"></span></p>
<h2><a name="myisam-innodb">MyISAM or InnoDB?</a></h2>
<p>Since we need reliability, I created different tests, search the internet etc. My main question was &#8211; what to use MyISAM or InnoDB? I found the <a href="http://www.mysqlperformanceblog.com/2007/01/08/innodb-vs-myisam-vs-falcon-benchmarks-part-1/">post on the MySQL Perfomance Blog</a> (also <a href="http://www.mysqlperformanceblog.com/2007/10/12/myisam-scalability-and-innodb-falcon-benchmarks/">this</a> and <a href="http://www.mysqlperformanceblog.com/2007/01/03/innodb-benchmarks/">this</a>) and came to the conclusion, that when SELECT&#8217;ing, InnoDB is definitely faster (or, at least, is not slower). In addition, it provides constraints mechanism and allows transactions. The only thing it doesn&#8217;t have is FULLTEXT search. One more disadvantage is slower inserts. However, 80% of DB usage in this project are SELECT queries without FULLTEXT. For the fulltext search I created MyISAM table with fields I need and it works fine. The project is finished, but there will be phase 2 and I&#8217;m thinking of introducing <a href="http://www.sphinxsearch.com/">Sphinx</a> there. Anybody has experience with it?<br />
So I came up with InnoDB storage engine.</p>
<h2><a name="structure">Optimizing structure</a></h2>
<p>Next important step is DB structure. I&#8217;ll give some background info about the project so you could better understand what I&#8217;m talking about. The site collects info from different UK shops. Then users can rate them, add some tags, create articles (called &#8220;looks&#8221;) and link that articles to the products they&#8217;re writing about. And the same (tags, comments, rating) applies to the looks. Here we come across with an interesting question. We can create structure of different types for this:</p>
<ul>
<li>Create 2 separate cross-tables for linking Rating to Look or Product</li>
<li>Create one cross-table and add additional field &#8220;type&#8221; there to differentiate between Product and Look entities</li>
</ul>
<p>See both variants in the following images:<br />
<div id="attachment_251" class="wp-caption aligncenter" style="width: 310px"><a href="http://programmersnotes.info/wp-content/uploads/2009/05/norm1.png"><img src="http://programmersnotes.info/wp-content/uploads/2009/05/norm-300x174.png" alt="Normalized variant" title="Normalized variant" width="300" height="174" class="size-medium wp-image-251" /></a><p class="wp-caption-text">Normalized variant</p></div><br />
<div id="attachment_252" class="wp-caption aligncenter" style="width: 310px"><a href="http://programmersnotes.info/wp-content/uploads/2009/05/denorm1.png"><img src="http://programmersnotes.info/wp-content/uploads/2009/05/denorm-300x157.png" alt="Denormalized version" title="Denormalized version" width="300" height="157" class="size-medium wp-image-252" /></a><p class="wp-caption-text">Denormalized version</p></div><br />
Initially I thought that the second variant would perform better, but after creating and running tests, I saw, that:</p>
<ul>
<li>If there are 0-2 ratings linked to entity, then normalized variant is better</li>
<li>If there are 3-5 ratings linked to entity, then denormalized variant is slightly (less than 1%) better</li>
<li>If there are 6-8 ratings linked to the entity, the normalized variant wins again</li>
</ul>
<p>I did these tests for different situations similar to this one, in each test I generated random records and randomly linked them with each other. Number of record in Product, Look tables was 10000, in Rating &#8211; 20000. Number of records in cross tables varies because the linkings are random.<br />
So I came up with normalizing everything like it should be done according to the DB theory.</p>
<p>The only exclusion of this rule is the following situation. In this project you can add different alternatives to the product. Each alternative is &#8220;better&#8221; or &#8220;cheaper&#8221; or &#8220;different&#8221; etc. And since the only case when these alternatives are pulled from DB is when user views the product, they are pulled altogether, so it is better to keep them in the same table.</p>
<h2><a name="conclusion">Conclusion</a></h2>
<ul>
<li>InnoDB turns out to behave better under the high load, it supports transactions and maintains constraints. All that helps to develop better and never leave orphan records.</li>
<li>Using normalization techniques you usually get better performance</li>
<li>Create tests and test everything if you are going to do something great <img src='http://programmersnotes.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<h4>Further reading</h4>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Database_normalization">Database Normalization</a></li>
<li><a href="http://www.mysqlperformanceblog.com/2007/01/08/innodb-vs-myisam-vs-falcon-benchmarks-part-1/">MySQL Performance Blog</a></li>
</ul>
<p>P.S. I&#8217;m looking forward to see your comments on implementation techniques in the high-loaded websites, your thoughts about the InnoDB vs MyISAM question and anything else you can think of <img src='http://programmersnotes.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d5').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Liked the post? Bookmark it</em></strong></a>
<br />
<div class="d5" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F&amp;title=Building+high-loaded+portal+%26%238211%3B+InnoDB+vs+MyISAM" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F&amp;title=Building+high-loaded+portal+%26%238211%3B+InnoDB+vs+MyISAM" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F&amp;title=Building+high-loaded+portal+%26%238211%3B+InnoDB+vs+MyISAM" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F&amp;T=Building+high-loaded+portal+%26%238211%3B+InnoDB+vs+MyISAM" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F&amp;title=Building+high-loaded+portal+%26%238211%3B+InnoDB+vs+MyISAM" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F&amp;title=Building+high-loaded+portal+%26%238211%3B+InnoDB+vs+MyISAM" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Building+high-loaded+portal+%26%238211%3B+InnoDB+vs+MyISAM+@+http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F05%2F20%2Fbuilding-high-loaded-portal-innodb-vs-myisam%2F&amp;t=Building+high-loaded+portal+%26%238211%3B+InnoDB+vs+MyISAM" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d5').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d5').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>

<p>Related posts:<ol><li><a href='http://programmersnotes.info/2009/10/06/low-coupling-and-high-cohesion-grasp-design-patterns/' rel='bookmark' title='Permanent Link: Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)'>Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)</a> <small>Low coupling When designing some architecture, you face with the...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://programmersnotes.info/2009/05/20/building-high-loaded-portal-innodb-vs-myisam/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Creator and Information Expert principles &#8211; GRASP (Design patterns series)</title>
		<link>http://programmersnotes.info/2009/03/28/creator-and-information-expert-grasp-design-pattern-series/</link>
		<comments>http://programmersnotes.info/2009/03/28/creator-and-information-expert-grasp-design-pattern-series/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 13:37:32 +0000</pubDate>
		<dc:creator>Konstantin Mirin</dc:creator>
				<category><![CDATA[Design patterns]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[grasp]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[polymorphism]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[UML]]></category>

		<guid isPermaLink="false">http://konstantin.takeforce.net/?p=13</guid>
		<description><![CDATA[Post gives an overview of design patterns, GRASP principles and explains first two of them. Everything is illustrated with code and practical examples.


Related posts:<ol><li><a href='http://programmersnotes.info/2009/10/06/low-coupling-and-high-cohesion-grasp-design-patterns/' rel='bookmark' title='Permanent Link: Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)'>Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)</a> <small>Low coupling When designing some architecture, you face with the...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<h2><a name="intro">Preface</a></h2>
<p>This is an introductory post to the series, where I&#8217;ll cover all design patterns, their usage, diagrams. Besides patterns, I am going to guide you through the principles of the high-quality application design. We&#8217;ll start from these principles (GRASP), and then advance to patterns, see how they use these principles and develop several systems (architecture only). The whole series will take 10-15 posts. However, I don&#8217;t have exact plan yet <img src='http://programmersnotes.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  So, let&#8217;s go!</p>
<h2>So what we&#8217;re talking about?</h2>
<p>Actually, design pattern is no more, than a proven solution to some common problem. When saying &#8220;problem&#8221; I mean things you face with when developing the application architecture. These solutions are intended to make you application better &#8211; more extensible, flexible, simple. </p>
<p>Common examples of design problems (Let&#8217;s agree that in this series &#8220;design&#8221; means application, not graphics or DB design) are:<br />
<span id="more-13"></span></p>
<ul>
<li>Organizing access to the shared resource. This can be application object, DB abstraction object, Session object or other similar things. Main problem is that they should be created only once and accessed in every method easily. Singleton pattern solves this problem.</li>
<li>Creating the easily extensible application. For example, code shopping cart in the way, that allows to add new payment or taxation modules easily. Adapter pattern saves us here.</li>
<li>Providing the simple interface for accessing features of the application or application module, hiding all the underlying classes/functions from the user. Façade pattern does this.</li>
<li>Separating data from data processing and from presentation. You&#8217;ve definitely heard about MVC (Model-View-Controller) &#8211; that&#8217;s also a pattern!</li>
</ul>
<p>So patterns are everywhere in OOP and knowing them is essential for high-quality and extensible application design.</p>
<h2><a name="basics">The basics</a></h2>
<p>However, patterns themselves are implementation of the 9 basic principles (GPASP &#8211; General Responsibility Assignment Software Principles).<br />
<div id="attachment_162" class="wp-caption aligncenter" style="width: 310px"><a href="http://programmersnotes.info/wp-content/uploads/2009/03/patterns1.png"><img src="http://programmersnotes.info/wp-content/uploads/2009/03/patterns-300x252.png" alt="GRASP and patterns" title="patterns" width="300" height="252" class="size-medium wp-image-162" /></a><p class="wp-caption-text">GRASP and patterns</p></div><br />
All OOP design is about creating real-world abstractions (classes), design methods (responsibilities) and their interaction. The key thing to good architecture is assigning responsibilities to the classes correctly. GRASP deals exclusively with this problem. We&#8217;ll go through all of them:</p>
<ul>
<li><a href="#creator">Creator</a></li>
<li><a href="#expert">Information Expert</a></li>
<li>Low Coupling</li>
<li>High Cohesion</li>
<li>Controller</li>
<li>Polymorphysm</li>
<li>Pure Fabrication</li>
<li>Indirection</li>
<li>Protected Variations</li>
</ul>
<p>Today we&#8217;ll start from the first principle.</p>
<h2><a name="creator">Creator</a></h2>
<p>The most common problem in OO design is &#8220;Who should create object X?&#8221; This principle states, that object A should create object B if:</p>
<ul>
<li><a href="#a_aggregates_b">A contains or aggregates B</a> (e.g. Object User should initialize object Address)</li>
<li><a href="#a_records_b">A records B</a> (saves to DB or file)</li>
<li>A closely uses B</li>
<li>A has the initialization data that should be passed to B when object is created</li>
</ul>
<p>If any of these conditions are true, then A should create B. Now let&#8217;s demonstrate how these principles work in real examples.</p>
<h3><a name="a_aggregates_b">A contains or aggregates B</a></h3>
<p>Consider we have table. Common table consists of desk and legs.<br />
<div id="attachment_166" class="wp-caption aligncenter" style="width: 310px"><a href="http://programmersnotes.info/wp-content/uploads/2009/03/table1.png"><img src="http://programmersnotes.info/wp-content/uploads/2009/03/table-300x277.png" alt="Common table" title="table" width="300" height="277" class="size-medium wp-image-166" /></a><p class="wp-caption-text">Common table</p></div><br />
If we use object decomposition to program the table, we&#8217;ll get 3 classes:</p>
<ul>
<li>
		Table (blue box on image):</p>
<ul>
<li>Desk (light grey)</li>
<li>Leg (wooden)</li>
</ul>
</li>
</ul>
<blockquote><p>Object decomposition basically means breaking some entity into parts and representing each part with a object. These parts can be decomposed further. For example, we can break Table into Desk and Leg. And then break Leg into Screw, Plank. In complex system there is a number of such levels.</p></blockquote>
<p>If we start programming this, we can go in 2 ways. For example, we don&#8217;t want to use the Creator principle and will create Table class as follows:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Table</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$desk</span>;<span class="co1">//desk object</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$legs</span>;<span class="co1">//array of legs</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span>Desk <span class="re0">$d</span>, <span class="re0">$l</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">desk</span> = <span class="re0">$dd</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">legs</span> = <span class="re0">$l</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Then Desk and Leg classes:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Desk</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$width</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$length</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$height</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re0">$w</span>, <span class="re0">$l</span>, <span class="re0">$h</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">width</span> = <span class="re0">$w</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">length</span> = <span class="re0">$l</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">height</span> = <span class="re0">$h</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Leg</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$width</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$length</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$height</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re0">$w</span>, <span class="re0">$l</span>, <span class="re0">$h</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">width</span> = <span class="re0">$w</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">length</span> = <span class="re0">$l</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">height</span> = <span class="re0">$h</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Yes, Desk and Leg classes are really the same cause they both are parallelepipeds. So we can create Parallelepiped class and extend both of them from it. We&#8217;ll do it later, now we&#8217;re talking about object creation. The above classes can be used in the following way:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$desk</span> = <span class="kw2">new</span> Desk<span class="br0">&#40;</span><span class="nu0">900</span>,<span class="nu0">900</span>,<span class="nu0">20</span><span class="br0">&#41;</span>;<span class="co1">//90 cm width, 90 length (square) and 2cm height. A normal table for kitchen <img src='http://programmersnotes.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$legs</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">new</span> Leg<span class="br0">&#40;</span><span class="nu0">40</span>,<span class="nu0">40</span>, <span class="nu0">880</span><span class="br0">&#41;</span>,<span class="co1">//4&#215;4 cm square and 88cm height. 88cm leg + 2 cm desk = 90cm full height</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">new</span> Leg<span class="br0">&#40;</span><span class="nu0">40</span>,<span class="nu0">40</span>, <span class="nu0">880</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">new</span> Leg<span class="br0">&#40;</span><span class="nu0">40</span>,<span class="nu0">40</span>, <span class="nu0">880</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">new</span> Leg<span class="br0">&#40;</span><span class="nu0">40</span>,<span class="nu0">40</span>, <span class="nu0">880</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$table</span> = <span class="kw2">new</span> Table<span class="br0">&#40;</span><span class="re0">$desk</span>, <span class="re0">$legs</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Yes, the object is created, but large part of the creation logic is outside of the object. The class user (the programmer who is using this class) should know the internal structure of objects to create the whole object. This approach is inefficient when we deal with large application; on the other side, such solution can&#8217;t be reused without changing the code. And it violates the first condition of using the Creator principle. Either Desk and Leg are parts of the Table object, so it should take care of their instantiation. So let&#8217;s learn how to solve such task correctly:<br />
We&#8217;ll create constructor for Table class with parameters:</p>
<ul>
<li>Width &#8211; width of the table</li>
<li>Length &#8211; length of the table</li>
<li>Height &#8211; height of the table</li>
<li>DeskHeight &#8211; height of the desk</li>
<li>LegSection &#8211; (assume we want square legs)</li>
</ul>
<p>So the end-user of the class should specify only these 5 parameters, we don&#8217;t ask him to create parts of our object. OK, let&#8217;s code it:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Table</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$desk</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; protected <span class="re0">$legs</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re0">$width</span>, <span class="re0">$length</span>, <span class="re0">$height</span>, <span class="re0">$deskHeight</span>, <span class="re0">$legSection</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">desk</span> = <span class="kw2">new</span> Desk<span class="br0">&#40;</span><span class="re0">$width</span>, <span class="re0">$length</span>, <span class="re0">$deskHeight</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span> = <span class="nu0">0</span>; <span class="re0">$i</span> &lt; <span class="nu0">4</span>; <span class="re0">$i</span>++<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">legs</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span> = <span class="kw2">new</span> Leg<span class="br0">&#40;</span><span class="re0">$legSection</span>, <span class="re0">$legSection</span>, <span class="re0">$height</span> &#8211; <span class="re0">$deskHeight</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Desk and Leg classes remain the same. So here we followed the first condition (actually, the most important) and got nice architecture.</p>
<h3><a name="a_records_b">A records B</a></h3>
<p>After detailed discussion of the first condition, this should be quite evident. Usually if some object saves another one, it is his part. For example, we have some system with users. Each user may have several addresses. So Address will be the part of User (it is quite logical to design so), and User object will save all addresses in one field (Using serialization). And when loading, it will load the address info from DB and create Address objects. This is example of both 2, 3 and 4 item. The User object saves Address. User object has initialization info for Address and user object closely uses Address. By the way, first item is also here, Address is part of User object.<br />
As you see, all these conditions often go together.<br />
I think, that the final 2 items should be evident.</p>
<h4>Further development</h4>
<p>Tasks for improvement your skills:</p>
<ul>
<li>Extend both Leg and Desk from the Parallelipiped class</li>
<li>Implement getHeight() method for Table, Desk and Leg. Hint: In Leg and Desk classes it should simply return height. In Table class it should return sum of leg height and Desk height</li>
<li>Implement setHeight method for all classes. Hint: when setting height for table, you should actually increment Leg&#8217;s height</li>
<li>Implement Saving and loading from file or DB. Hint: actually you have to save only 5 parameters &#8211; those passed to table constructor. So when saving and loading Table class with interact with Desk and Leg classes. And when loading &#8211; will create these classes.</li>
</ul>
<h2><a name="expert">Information Expert</a></h2>
<p>The last condition of applying the Creator principle shows, that object A should have all info about B to create it. In other words, A should be <em>Expert</em> in info about B. Information Expert principle helps us assigning all responsibilities in the project. Real-world application usually holds a number of classes, that perform hundreds and thousands of actions, so it is essential to assign responsibilities correctly. The principle itself is fairly simple &#8211; you should give the responsibilities to the object it has information for. For example, assigning Table class responsibility to create Desk is correct because it has info about it. Assigning User responsibility to save data to DB is also correct, because User holds data about user and can perform this task without any other objects (assuming it deals with DB without DB abstraction layer). And assigning User to save information about Group is incorrect, because User will have to &#8220;ask&#8221; Group about it&#8217;s properties &#8211; ID, name, access rights etc. in order to save it correctly. In this case it&#8217;s much better to assign Group responsibility to save itself. And Use can call save() method on Group object.</p>
<p>In the next post I&#8217;ll cover Low Coupling and High Cohesion principles and illustrate it with practical examples. Subscribe to RSS not to miss it!<br />
Feel free to ask any questions in comments or by email: <a href="mailto:konstantin.mirin[at]programmersnotes.info">konstantin.mirin[at]programmersnotes.info</a></p>
<h4>Further reading</h4>
<ul>
<li><a href="http://en.wikipedia.org/wiki/GRASP_(Object_Oriented_Design)">GRASP</a></li>
<li><a href="http://en.wikipedia.org/wiki/Craig_Larman">Larman, Craig</a> (2005). Applying UML and Patterns &#8211; An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd ed.). Prentice Hall PTR. ISBN 0-13-148906-2.</li>
</ul>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d13').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Liked the post? Bookmark it</em></strong></a>
<br />
<div class="d13" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F&amp;title=Creator+and+Information+Expert+principles+%26%238211%3B+GRASP+%28Design+patterns+series%29" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F&amp;title=Creator+and+Information+Expert+principles+%26%238211%3B+GRASP+%28Design+patterns+series%29" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F&amp;title=Creator+and+Information+Expert+principles+%26%238211%3B+GRASP+%28Design+patterns+series%29" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F&amp;T=Creator+and+Information+Expert+principles+%26%238211%3B+GRASP+%28Design+patterns+series%29" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F&amp;title=Creator+and+Information+Expert+principles+%26%238211%3B+GRASP+%28Design+patterns+series%29" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F&amp;title=Creator+and+Information+Expert+principles+%26%238211%3B+GRASP+%28Design+patterns+series%29" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Creator+and+Information+Expert+principles+%26%238211%3B+GRASP+%28Design+patterns+series%29+@+http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F28%2Fcreator-and-information-expert-grasp-design-pattern-series%2F&amp;t=Creator+and+Information+Expert+principles+%26%238211%3B+GRASP+%28Design+patterns+series%29" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d13').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d13').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>

<p>Related posts:<ol><li><a href='http://programmersnotes.info/2009/10/06/low-coupling-and-high-cohesion-grasp-design-patterns/' rel='bookmark' title='Permanent Link: Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)'>Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)</a> <small>Low coupling When designing some architecture, you face with the...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://programmersnotes.info/2009/03/28/creator-and-information-expert-grasp-design-pattern-series/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Working with large files eficiently</title>
		<link>http://programmersnotes.info/2008/06/16/working-with-large-files-eficiently/</link>
		<comments>http://programmersnotes.info/2008/06/16/working-with-large-files-eficiently/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 16:59:20 +0000</pubDate>
		<dc:creator>Konstantin Mirin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[file]]></category>

		<guid isPermaLink="false">http://konstantin.takeforce.net/?p=3</guid>
		<description><![CDATA[Once I had a task to import a number of data from datafeeds (that are in CSV or XML) into MySQL database. See solution in my another post. Here I want to tell about handling large files.
Datafeeds there are 50-200M each, so reading all file at once was not possible due to memory limitations. So [...]


Related posts:<ol><li><a href='http://programmersnotes.info/2009/10/06/low-coupling-and-high-cohesion-grasp-design-patterns/' rel='bookmark' title='Permanent Link: Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)'>Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)</a> <small>Low coupling When designing some architecture, you face with the...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Once I had a task to import a number of data from datafeeds (that are in CSV or XML) into MySQL database. See solution in my another post. Here I want to tell about handling large files.</p>
<p>Datafeeds there are 50-200M each, so reading all file at once was not possible due to memory limitations. So we need to split it into portions. Here is the class, that solves the problem of downloading remote file, saving it locally and then reading by portions.<span id="more-19"></span> Position is saved in $this->Offset:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> WebServiceSource implements GenericSource</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$URI</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$TempFile</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$URIHandler</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$TMPHandler</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$Data</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$Offset</span> = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="re0">$EOF</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* Size to read from remote host at once, buffer</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; const BUFFER_LENGTH = <span class="nu0">102400</span>;<span class="co1">//1 MB</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;* Number of records to read at once, from the local file</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; const RECORDS_NUM = <span class="nu0">15</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re0">$uri</span> = <span class="kw2">NULL</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">SetURI</span><span class="br0">&#40;</span><span class="re0">$uri</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">EOF</span> = <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> OpenURI<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">URIHandler</span> = @<a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">URI</span>, <span class="st0">&#8216;r&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="re0">$this</span>-&gt;<span class="me1">URIHandler</span><span class="br0">&#41;</span> throw <span class="kw2">new</span> ASException<span class="br0">&#40;</span><span class="st0">&#8216;WrongDatafeedURL&#8217;</span>, <span class="st0">&#8216;DFImport&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> OpenTempFile<span class="br0">&#40;</span><span class="re0">$mode</span> = <span class="st0">&#8216;w+&#8217;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">TMPHandler</span> = @<a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">TempFile</span>, <span class="re0">$mode</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="re0">$this</span>-&gt;<span class="me1">TMPHandler</span><span class="br0">&#41;</span> throw <span class="kw2">new</span> ASException<span class="br0">&#40;</span><span class="st0">&#8216;TempFileNotAccessible&#8217;</span>, <span class="st0">&#8216;DFImport&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> CloseURI<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">URIHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> CloseTempFile<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">TMPHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> IsDownloaded<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/file_exists"><span class="kw3">file_exists</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">TempFile</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><a href="http://www.php.net/time"><span class="kw3">time</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span> &#8211; <a href="http://www.php.net/filectime"><span class="kw3">filectime</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">TempFile</span><span class="br0">&#41;</span><span class="br0">&#41;</span> &gt; TMP_EXPIRE<span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> Download<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">IsDownloaded</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">return</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// &nbsp; &nbsp; &nbsp; &nbsp;set_time_limit(0);</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">OpenURI</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">OpenTempFile</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/feof"><span class="kw3">feof</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">URIHandler</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$buffer</span> = <a href="http://www.php.net/fread"><span class="kw3">fread</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">URIHandler</span>, self::<span class="me2">BUFFER_LENGTH</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/fwrite"><span class="kw3">fwrite</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">TMPHandler</span>, <span class="re0">$buffer</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">CloseURI</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">CloseTempFile</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> GetFragment<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">OpenTempFile</span><span class="br0">&#40;</span><span class="st0">&#8216;r&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$RecordsNum</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">Data</span> = <span class="st0">&#8221;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/fseek"><span class="kw3">fseek</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">TMPHandler</span>, <span class="re0">$this</span>-&gt;<span class="me1">Offset</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$row</span> = <a href="http://www.php.net/fgets"><span class="kw3">fgets</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">TMPHandler</span><span class="br0">&#41;</span><span class="br0">&#41;</span> &amp;&amp; <span class="re0">$RecordsNum</span> &lt;= self::<span class="me2">RECORDS_NUM</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">Data</span> .= <span class="re0">$row</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$RecordsNum</span>++;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//if number of records read is less then maximum, then we came to the</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// end of file</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$RecordsNum</span> &lt; self::<span class="me2">RECORDS_NUM</span><span class="br0">&#41;</span> <span class="re0">$this</span>-&gt;<span class="me1">EOF</span> = <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">Offset</span> = <a href="http://www.php.net/ftell"><span class="kw3">ftell</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">TMPHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">CloseTempFile</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$this</span>-&gt;<span class="me1">Data</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> GetData<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">Download</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="re0">$this</span>-&gt;<span class="me1">EOF</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$this</span>-&gt;<span class="me1">GetFragment</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> SetURI<span class="br0">&#40;</span><span class="re0">$uri</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">URI</span> = <span class="re0">$uri</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">TempFile</span> = SYSTEM_ROOT.TMP_DIR.<a href="http://www.php.net/md5"><span class="kw3">md5</span></a><span class="br0">&#40;</span><span class="re0">$uri</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>And here is an example of how it works:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$source</span> = <span class="kw2">new</span> WebServiceSource<span class="br0">&#40;</span><span class="re0">$url</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">while</span> <span class="br0">&#40;</span><span class="re0">$res</span> = <span class="re0">$this</span>-&gt;<span class="me1">Source</span>-&gt;<span class="me1">GetData</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">Parser</span>-&gt;<span class="me1">SetRawData</span><span class="br0">&#40;</span><span class="re0">$res</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">Parser</span>-&gt;<span class="me1">Parse</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d19').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Liked the post? Bookmark it</em></strong></a>
<br />
<div class="d19" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F&amp;title=Working+with+large+files+eficiently" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F&amp;title=Working+with+large+files+eficiently" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F&amp;title=Working+with+large+files+eficiently" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F&amp;T=Working+with+large+files+eficiently" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F&amp;title=Working+with+large+files+eficiently" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F&amp;title=Working+with+large+files+eficiently" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Working+with+large+files+eficiently+@+http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fprogrammersnotes.info%2F2008%2F06%2F16%2Fworking-with-large-files-eficiently%2F&amp;t=Working+with+large+files+eficiently" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d19').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d19').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>

<p>Related posts:<ol><li><a href='http://programmersnotes.info/2009/10/06/low-coupling-and-high-cohesion-grasp-design-patterns/' rel='bookmark' title='Permanent Link: Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)'>Low Coupling and High Cohesion &#8211; GRASP (Design patterns series)</a> <small>Low coupling When designing some architecture, you face with the...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://programmersnotes.info/2008/06/16/working-with-large-files-eficiently/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
