<?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>Luminis Software Development &#187; design</title>
	<atom:link href="http://lsd.luminis.eu/en/tag/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://lsd.luminis.eu</link>
	<description></description>
	<lastBuildDate>Wed, 28 Dec 2011 20:44:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Uncle Bob in da house: how to write clean code</title>
		<link>http://lsd.luminis.eu/en/uncle-bob-in-da-house-how-to-write-clean-code/</link>
		<comments>http://lsd.luminis.eu/en/uncle-bob-in-da-house-how-to-write-clean-code/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 12:25:13 +0000</pubDate>
		<dc:creator>Richard de Zwart</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[News Item]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=1089</guid>
		<description><![CDATA[(Nederlands) Robert C. Martin was een uur lang te gast op de HAN in Arnhem en hield een vlammend betoog over het schrijven van Clean Code.]]></description>
			<content:encoded><![CDATA[<p>Gisterenavond (16 september) was Arnhem in de gelukkige omstandigheid dat <a href="http://objectmentor.com/omTeam/martin_r.html">Robert C. Martin</a> de uitnodiging had aangenomen van de HAN om een verhaal te komen houden. Het onderwerp: <a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code</a>.</p>
<p>Robert Martin (die ook schrijft onder de naam <a href="http://butunclebob.com/ArticleS.UncleBob">Uncle Bob</a>) is een geweldige spreker en een wereldberoemd schrijver van publicaties over software craftmanship. Hij is dermate gepassioneerd over het op een hoger niveau brengen van ons vak, dat hij zelfs voor een groepje jonge engineers die de schoolbanken nog niet hebben verlaten een vlammend betoog komt houden.</p>
<p>Hij raasde in een uur tijd door zijn slides over Clean Code heen, lardeerde dat met leuke verhalen en analogieën en onderbouwde zijn betoog met praktijk voorbeelden. Hieronder een greep uit de tips die we kregen over het schrijven van functies.</p>
<h3>Leesbaarheid</h3>
<p>Eigenlijk gaan alle onderstaande tips over de leesbaarheid van de code. Iemand die jouw code ziet (en dat kun je ook goed zelf zijn) moet met lichte verveling van boven naar beneden door je code kunnen gaan, waarbij de code steeds gedetailleerder wordt.<br />
- &#8220;Ja&#8221;<br />
- &#8220;Mmmh, mmh&#8221;<br />
- &#8220;Duidelijk&#8221;<br />
- &#8220;Ja&#8221;<br />
- &#8220;Logisch&#8221;<br />
Totdat de code een nivo van detaillering bereikt dat je als lezer denkt &#8220;Ja, ja, nu begrijp ik het wel. Saai&#8221;. Dan heb je het goed gedaan. Saaie code, waar niemand lang bij hoeft stilt te staan (want daar heb je gewoon geen tijd voor). Niemand zit te wachten op briljante code, behalve jouw ego. Briljante code is de eerste code die ik vervang als ik onderhoud moet doen; vervang door saaie, begrijpelijke code.</p>
<h3>Descriptive names</h3>
<p>Gebruik een naam voor je functie die zegt wat de functie doet. Dus niet &#8220;Process()&#8221; maar &#8220;AddOrderLineToOrder()&#8221;.</p>
<h3>Do One Thing</h3>
<p>Een functie moet slechts 1 ding doen. Als een functie 2 dingen doet, moet je &#8216;m in 2 functies opdelen. De functie &#8220;AddOrderAndCalculateTotals()&#8221; wordt dan dus &#8220;AddOrder()&#8221; en &#8220;CalculateTotalsForOrder()&#8221;.</p>
<h3>Small functions</h3>
<p>Functies mogen niet meer dan 4 regels lang zijn (tussen de accolades). Het liefst 2 of 3, maar als het echt moet dan kan 4 ook. Een functie moet eigenlijk niet veel meer doen dan bijvoorbeeld een test uitvoeren in een if-statement en dan een andere functie aanroepen. En de test in de if is natuurlijk ook een functie.<br />
Hoe kom je aan kleine functies? Die kun je niet van scratch af aan maken. Je maakt eerst je bekende grote bak code van wel 20 of 30 regels, zodat je je test aan de praat kan krijgen (je weet wel <a href="http://en.wikipedia.org/wiki/Test-driven_development">&#8220;Red-Green-Refactor&#8221;</a>). Daarna ga je je grote functie opknippen met een van de standaard Refactor-tools die jouw IDE ondersteunt, meestal &#8220;ExtractMethod&#8221; geheten. En na elke ExtractMethod draai je je tests om te weten of je niets stuk gemaakt hebt.</p>
<h3>No error codes</h3>
<p>Functies moeten exceptions gebruiken en try/catch blocks. Binnen een try moet bij voorkeur 1 regel code staan: de aanroep van een functie.<br />
Return-codes zijn om iets nuttigs terug te geven aan de aanroepende code, bijvoorbeeld een Boolean als je functie &#8220;IsValidDate()&#8221; heet, maar niet om te laten weten dat er iets is mis gegaan. Error-codes leiden tot veel geneste if&#8217;s en tot out-parameters (zie verderop).</p>
<h3>No more than 3 parameters</h3>
<p>Een functie heeft bij voorkeur geen parameters, dat leest het makkelijkst, maar is niet zo realistisch. Als een functie meer data dan 3 parameters nodig heeft om zijn werk te kunnen doen, moet je gaan refactoren. Waarschijnlijk hoort al die data bij elkaar in één class.</p>
<h3>No out-parameters and no boolean-parameters</h3>
<p>Een functie heeft dingen aan de rechterkant (parameters) die erin gaan en een ding aan de linkerkant (return-value) die eruit komt. Als er dingen aan de rechterkant uitkomen verwar je de lezer enorm. Tijd voor een refactoring.<br />
Booleans lezen helemaal moeilijk en verraden dat je eigenlijk een functie hebt die 2 dingen doet, gestuurd door de vlag die je erin stop.<br />
Wat doet het onderstaande?</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var html <span style="color: #008000;">=</span> GetHtmlForControl<span style="color: #000000;">&#40;</span>button, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Zou het niet beter zijn om 2 functies te hebben die beter laten zien wat ze doen?</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> GetUnformattedHtmlForControl<span style="color: #000000;">&#40;</span>button<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span> ... <span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> GetFormattedHtmlForControl<span style="color: #000000;">&#40;</span>button<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span> ... <span style="color: #000000;">&#125;</span></pre></div></div>

<h3>Unit tests</h3>
<p>Als je geen unit-test hebt kun je nooit bewijzen (voor jezelf, je teamgenoten of je baas) dat de code die je gemaakt hebt echt werkt.<br />
Accountants controleren hun eigen werk door elke boeking 2 keer op te nemen: &eacute;&eacute;n keer aan de debet kant en &eacute;&eacute;n keer aan de credit kant. Onderaan moet dan nul staan. Je kunt nog steeds de pech hebben dat je twee fouten hebt gemaakt die elkaar precies opheffen, maar die kans is niet zo groot. In ieder geval heb je een Standard Practice toegepast.<br />
Dat kunnen wij software-engineers minstens even goed doen. Code schrijven en tests schrijven. </p>
<h3>Design Patterns</h3>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2010/09/DesignPatterns.jpg"><img src="http://lsd.luminis.nl/wp-content/uploads/2010/09/DesignPatterns-300x300.jpg" alt="DesignPatterns" title="DesignPatterns" width="300" height="300" class="alignright size-medium wp-image-1093" /></a>Ken je patterns. Het boek van de Gamma et al is volgens Robert Martin het belangrijkste boek dat de afgelopen 20 jaar is geschreven op het gebied van software design.</p>
<h3>Maar daar hebben we geen tijd voor!</h3>
<p>Je zult het zelf misschien onmiddellijke roepen als je bovenstaande hebt gelezen: &#8220;Allemaal leuk en aardig, en ja, ik wil goeie code schrijven, maar het moet af, ik heb hier echt geen tijd voor&#8221;.<br />
Fout. Als je het op bovenstaande manier doet, houd je tijd over. Om de simpele reden dat iedereen gedurende het project zijn bestaande code moet uitbreiden, aanpassen, verbeteren of overdragen. Als je clean-code schrijft dan kost dat wroeten in je eigen code je veel minder tijd dan wanneer je de gebruikelijke bak spaghetti heb geschreven. En omdat je unit-tests hebt,  weet je ook dat je aanpassing niets stuk gemaakt heeft.</p>
<p>Robert Martin haalde het voorbeeld aan van Hongaarse arts <a href="http://en.wikipedia.org/wiki/Ignaz_Semmelweis">Ignaz Semmelweis</a> die ontdekte dat het aantal vrouwen dat overleed in het kraambed van 8 op de 10 zakte naar 1 op de 100 als je eerst je handen waste nadat je een autopsie had gedaan. Hij begreep niet waarom, maar stelde onomstotelijk vast dat het werkte. Desalniettemin duurde het tot vele jaren na zijn dood voordat deze activiteit tot het standaard repertoire van de arts ging behoren.</p>
<p>Zou jij tegen je chirurg zeggen vlak voordat je de operatiekamer ingereden werd &#8220;Laat dat handen wassen maar achterwegen hoor, daar heb je helemaal geen tijd voor&#8221;? Vast niet. En omgekeerd? Als jouw patiënt dat zou zeggen, zou je dan naar hem luisteren?<br />
In jouw vak ben jij de chirurg en is je opdrachtgever degene die onder het mes gaat.</p>
<h3>Word een professional</h3>
<p>Wij zijn geen loonwerkers, ons werk is niet te vergelijken met het op elkaar stapelen van stenen. En onze verantwoordelijkheid gaat verder dan &#8220;maar hij heeft gezegd dat dat zo moest&#8221;. Als professional heb je de plicht om tegen je opdrachtgever/klant/baas &#8220;nee&#8221; te zeggen als hij/zij vraagt om iets slechts af te leveren.<br />
- &#8220;Kun je het niet zonder tests?&#8221;<br />
- &#8220;Nee&#8221;<br />
- &#8220;Maar daar hebben we geen tijd voor!&#8221;<br />
- &#8220;Dus er mogen bugs zitten in mijn werk?&#8221;<br />
- &#8220;Uh, nou ja, het hoeft niet perfect te zijn&#8221;<br />
- &#8220;Als er bugs in mogen zitten, dan ben ik klaar wanneer je wilt. Nu al, feitelijk&#8221;<br />
- &#8220;Kom op, je begrijpt best wat ik bedoel&#8221;<br />
- &#8220;Nee, wil je nou dat ik m&#8217;n handen was of niet?&#8221;<br />
- &#8230;..?</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.eu/en/uncle-bob-in-da-house-how-to-write-clean-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building iPhone applications using MonoTouch, part 5: software design considerations</title>
		<link>http://lsd.luminis.eu/en/building-iphone-applications-using-monotouch-part-5-software-design-considerations/</link>
		<comments>http://lsd.luminis.eu/en/building-iphone-applications-using-monotouch-part-5-software-design-considerations/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 21:26:55 +0000</pubDate>
		<dc:creator>Richard de Zwart</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[mobility]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[MonoDevelop]]></category>
		<category><![CDATA[monotouch]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=574</guid>
		<description><![CDATA[In this post I try to determine where some of my code should go and how I can keep the my application loosely coupled and tightly coherent.]]></description>
			<content:encoded><![CDATA[<p>In the previous 4 posts (<a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-4-the-uisearchdisplaycontroller/">4</a>, <a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-part-3-the-interface-builder/">3</a>, <a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-2/">2</a>, <a href="http://lsd.luminis.nl/building-iphone-applications-using-monotouch-1/">1</a>) I gave a lot of attention to the overall structure of an iPhone application. In this post I want to talk about  a topic that is more concerned with general software design issues: where do I do what?</p>
<h3>Get SOLID</h3>
<p>There are two things that I always try to keep in mind when making software: loose coupling and tight cohesion. In other words:</p>
<ol>
<li>make sure your classes don&#8217;t know things that they don&#8217;t need to know</li>
<li>make sure your classes are good at one thing and one thing only</li>
</ol>
<p>These guidelines are part of the <a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod">5 SOLID principles</a> of class design by <a href="http://www.objectmentor.com/omTeam/martin_r.html">Uncle Bob Martin</a>:</p>
<ol>
<li>Single Responsibility Principle</li>
<li>Open Closed Principle</li>
<li>Liskov Substitution Principle</li>
<li>Interface Segregation Principle</li>
<li>Dependency Inversion Principle</li>
</ol>
<p>This stuff is really interesting and sort-of scientific, but it is also like making your database comply to the 5-th Normal Form: nobody does that. You&#8217;re happy with a 3rd Normal Form database. So I&#8217;m happy when I see code that complies with at least two of the above principles.</p>
<p>So what I do when building my iPhone apps is constantly asking myself: should this code be in this place? Sometimes I know right away that the answer is No, but still leave it there until I have a better idea on where to put it then. And with the (for me) rather unusual structure that the Cocao Framework forces upon me, it may take some time before I eventually find out where to put it.</p>
<p>Let me give you an example.</p>
<p>When you want to load data into a UITableView you must create a UITableViewDataSource and assign that to the DataSource property of your UITableViewController. Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> FinishedLaunching <span style="color: #000000;">&#40;</span>UIApplication app, NSDictionary options<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	tableView.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	window.<span style="color: #0000FF;">AddSubview</span> <span style="color: #000000;">&#40;</span>tableView<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	window.<span style="color: #0000FF;">MakeKeyAndVisible</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The class instantiated at line 3 is something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LeesPlankjeDataSource <span style="color: #008000;">:</span> UITableViewDataSource
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> woordjes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span><span style="color: #666666;">&quot;aap&quot;</span>, <span style="color: #666666;">&quot;noot&quot;</span>, <span style="color: #666666;">&quot;mies&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> UITableViewCell GetCell <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewCell cell <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DequeueReusableCell</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cell <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			cell <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UITableViewCell<span style="color: #000000;">&#40;</span>UITableViewCellStyle.<span style="color: #0600FF;">Default</span>, <span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		cell.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> woordjes<span style="color: #000000;">&#91;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> cell<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">int</span> RowsInSection <span style="color: #000000;">&#40;</span>UITableView tableview, <span style="color: #FF0000;">int</span> section<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> woordjes.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>On  line 3 you see the actual &#8220;data store&#8221;, and on line 4 an important override. This method gets called by Cocoa when loading data in your UITableView. So the controller has a data source and the appropriate methods get called by the framework.</p>
<h3>On to a more realistic implementation</h3>
<p>If I want to advance my class a bit, I could imagine that the data is not a fixed array of strings, but gets passed in at construction time. Maybe I read from a file or from a URL.</p>
<p>That changes my class to this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LeesPlankjeDataSource <span style="color: #008000;">:</span> UITableViewDataSource
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> _dataStorage<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> data<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_dataStorage <span style="color: #008000;">=</span> data<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> UITableViewCell GetCell <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewCell cell <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DequeueReusableCell</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cell <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			cell <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UITableViewCell<span style="color: #000000;">&#40;</span>UITableViewCellStyle.<span style="color: #0600FF;">Default</span>, <span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		cell.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> _dataStorage<span style="color: #000000;">&#91;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> cell<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">int</span> RowsInSection <span style="color: #000000;">&#40;</span>UITableView tableview, <span style="color: #FF0000;">int</span> section<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> _dataStorage.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And the main.cs gets these lines:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> woordjes <span style="color: #008000;">=</span> File.<span style="color: #0000FF;">ReadAllLines</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;woordjes.txt&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	tableView.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span>woordjes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Make sure when you have files that you want to be deployed with your app to set the build-action on the file to &#8220;content&#8221;:</p>
<p><a href="http://lsd.luminis.nl/wp-content/uploads/2009/11/BuildAction.png"><img class="alignleft size-medium wp-image-577" style="margin-left: 5px; margin-right: 5px;" title="BuildAction" src="http://lsd.luminis.nl/wp-content/uploads/2009/11/BuildAction-300x255.png" alt="BuildAction" width="300" height="255" /></a>That&#8217;s all neat. The DataSource gets it data from the outside and doesn&#8217;t care if it comes from a file or a network-connection.</p>
<p>So now we want some action when the user taps a row. You have no choice but to implement this in a delegate (a UITableViewDelegate of course) and then override the RowSelected() method. This method is called for you by Cocoa and as parameters you get a UITableView that the tapping happened on and the Row number that was tapped:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LeesPlankjeViewDelegate <span style="color: #008000;">:</span> UITableViewDelegate
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> RowSelected <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>But what can I do in this method? Let&#8217;s say I want to do a MessageBox-ish thing to show what word was chosen. All I have is an index to the row in my data source. But I don&#8217;t have the data source itself in this class. I need some way to acces my original data store.</p>
<p>I could do somehting like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> RowSelected <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #FF0000;">string</span> message <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DataSource</span>.<span style="color: #0000FF;">GetCell</span><span style="color: #000000;">&#40;</span>tableView,  indexPath<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var alert <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UIAlertView <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span>, message, <span style="color: #0600FF;">null</span>, <span style="color: #666666;">&quot;OK&quot;</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		alert.<span style="color: #0000FF;">Show</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So I ask the TableView for its data source, then ask the data source to give me the cell that is on the given index, and then ask the cell for the text of the label. It works, but it is butt-ugly. Why? Because now the delegate knows about the data source too. And I think it shouldn&#8217;t, because all the delegate needs to do is handle UI-interactions from the user. It should say &#8220;Hey, someone tapped me on this row, do something with it&#8221; and then leave the actual work to someone else.</p>
<p>I think it would be reasonable to leave the work to the controller. For me, a controller is always the man-in-the-middle, doing the real work brokering between the model and the view. But if I choose that, I have to pass in the controller when constructing the Delegate, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">tableView.<span style="color: #FF0000;">Delegate</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeViewDelegate<span style="color: #000000;">&#40;</span>tableViewController<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>And since the tableViewController is only known so far in the Interface Builder, I have to make the controller available in my code by creating an outlet. Sigh&#8230;. even more code in my FinishedLaunching() method. I don&#8217;t want that, I want to hook up UI-parts with each other using the Interface Builder, not in code.</p>
<p>So, what to do now? I don&#8217;t know yet. Let me first deal with a problem that I didn&#8217;t tell you about yet. It is in the code of the LeesPlankjeDataSource. I gave my LeesPlankjeDataSource a constuctor that accepts a string array, thereby enabling me to pass in the data that the data source needs to build a UITableView from.</p>
<p>The problem is, that the UISearchDisplayController re-uses my UITableViewController, including the DataSource. When I click search, it first simply overlays my view, but when I start typing in the search box, the ShouldReloadForSearchString () method gets called and that one resets the SearchResultDataSource with a filtered version of my LeesPlankjeDataSource:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> ShouldReloadForSearchString <span style="color: #000000;">&#40;</span>UISearchDisplayController controller, <span style="color: #FF0000;">string</span> forSearchString<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;In ShouldReloadForSearchtring&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	controller.<span style="color: #0000FF;">SearchResultsDataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span>forSearchString<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And how am I gonna feed this baby with the right data? How is the SearchResultsDataSource going to get a filtered list of the words in my &#8220;woordjes.txt&#8221; file? I chose to filter by using an overloaded constructor, but I could move that code to a normal method. That allows me to use the other constructor, passing in the data as before in the main.cs:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> ShouldReloadForSearchString <span style="color: #000000;">&#40;</span>UISearchDisplayController controller, <span style="color: #FF0000;">string</span> forSearchString<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;In ShouldReloadForSearchString&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	var woordjes <span style="color: #008000;">=</span> <span style="color: #008000;">?????????</span>
	var data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LeesPlankjeDataSource<span style="color: #000000;">&#40;</span>woordjes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	controller.<span style="color: #0000FF;">SearchResultsDataSource</span> <span style="color: #008000;">=</span> data.<span style="color: #0000FF;">FilterOn</span><span style="color: #000000;">&#40;</span>forSearchString<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>But where am I gonna get the &#8220;woordjes&#8221; variable from? Should I load the file again, like I did in main.cs? Or maybe my DataSource should know something about the model? In that case I will not pass data from the outside, but let the DataSource find out itself where to get the data. But that is so against the Dependency Inversion Principle (or Inversion of Control)! If classes depend on other classes, these dependencies had best be passed in from the outside, probably on construction time.</p>
<p>Shoot, I love the IoC pattern. Should I let it go, for the sake of simplicity? After all, I argued before that even the MVC-pattern was maybe to much of a burden for the simple applications we build on the iPhone most of the time.</p>
<p>For tonight, I give up. The <a href="http://lsd.luminis.nl/wp-content/uploads/2009/11/SearchProblems2.zip">code you can download</a> contains the solution that goes against IoC, but works none the less.</p>
<p>I would love to hear your ideas about how to build iPhone applications that are tightly coherent and loosely coupled. I know that we can get in some philosophical or religious discussions, but we&#8217;ll see what to do then. I just want to learn from you guys, as much as I want to teach you where I can.</p>
<p>P.S.<br />
Thanks to <a href="http://www.alexyork.net/blog/post/UINavigationController-with-MonoTouch-Building-a-simple-RSS-reader-Part-1.aspx">Alex York&#8217;s excellent post</a> (see his comment below) I was able to improve on my code. I had seen the idea of nesting the DataSource and Delegate into the UITableViewController before, but didn&#8217;t like it then. That dislike mostly came from the fact that you have to inherit from another class. There is no tighter couling between two classes then inheritance, so I believe you should only use it when absolutely necessary. Well, by now I think that it is absolutely necessary to inherit from the classes in the Cocoa framework. It is simply the way you work.</p>
<p>When working on the new solution I also renamed some classes (no more Dutch names, only Dutch words in the data&#8230;) and added a class that implements the model:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> WordsModel
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> List _dataStorage<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> WordsModel <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_dataStorage <span style="color: #008000;">=</span> File.<span style="color: #0000FF;">ReadAllLines</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;woordjes.txt&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		_dataStorage.<span style="color: #0000FF;">Sort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> Data <span style="color: #000000;">&#123;</span>
		get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _dataStorage.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> FilterOn<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> searchText<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		searchText <span style="color: #008000;">=</span> searchText.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		var result <span style="color: #008000;">=</span> _dataStorage.<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>t <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> t.<span style="color: #0000FF;">ToLowerInvariant</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span>searchText<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> result.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It is the place where the knowledge of words, where they come from and how you filter them, resides.</p>
<p>But Alex&#8217;s solution did not solve the problem that is typical of the use of the UISearchDisplayController: you have two instances of your DataSource: the one for your initial view, that just displays all the data (words in my case), and the one that is called upon by the UISearchDelegate when you start to search and filter.</p>
<p>I solved this by implementing a general WordsDataSource that uses the WordsModel and has a constuctor for normal use and for filtering:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> WordsDataSource <span style="color: #008000;">:</span> UITableViewDataSource
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> WordsModel model <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WordsModel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> _dataStorage<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> WordsDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_dataStorage <span style="color: #008000;">=</span> model.<span style="color: #0000FF;">Data</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> WordsDataSource<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> filter<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_dataStorage <span style="color: #008000;">=</span> model.<span style="color: #0000FF;">FilterOn</span><span style="color: #000000;">&#40;</span>filter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GetAt<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> position<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> _dataStorage<span style="color: #000000;">&#91;</span>position<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> UITableViewCell GetCell <span style="color: #000000;">&#40;</span>UITableView tableView, MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">NSIndexPath</span> indexPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewCell cell <span style="color: #008000;">=</span> tableView.<span style="color: #0000FF;">DequeueReusableCell</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cell <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			cell <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UITableViewCell<span style="color: #000000;">&#40;</span>UITableViewCellStyle.<span style="color: #0600FF;">Default</span>, <span style="color: #666666;">&quot;plankje&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		cell.<span style="color: #0000FF;">TextLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> _dataStorage<span style="color: #000000;">&#91;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> cell<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">int</span> RowsInSection <span style="color: #000000;">&#40;</span>UITableView tableview, <span style="color: #FF0000;">int</span> section<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> _dataStorage.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It inherits (yep I used the I-word) from UITableViewDataSource so can be called upon by the Cocoa framework when rendering the data for the UITableView.</p>
<p>And then I used that class in two places:</p>
<ol>
<li>as an internal property in my WordsTableViewController</li>
<li>as a helper-class in the delegate of the UISearchDisplayController.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WordsTableViewController&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> WordsTableViewController <span style="color: #008000;">:</span> UITableViewController
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Constructor invoked from the NIB loader</span>
    <span style="color: #0600FF;">public</span> WordsTableViewController <span style="color: #000000;">&#40;</span>IntPtr p<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span> <span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// The data source for our TableView</span>
    <span style="color: #0600FF;">private</span> WordsDataSource TableDataSource
    <span style="color: #000000;">&#123;</span>
	get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TableView</span>.<span style="color: #0000FF;">DataSource</span> <span style="color: #0600FF;">as</span> WordsDataSource<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TableView</span>.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// This class receives notifications that happen on the UITableView</span>
    <span style="color: #FF0000;">class</span> TableDelegate <span style="color: #008000;">:</span> UITableViewDelegate
    <span style="color: #000000;">&#123;</span>
	WordsTableViewController parentView<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> TableDelegate <span style="color: #000000;">&#40;</span>WordsTableViewController tableViewController<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
		parentView <span style="color: #008000;">=</span> tableViewController<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> RowSelected <span style="color: #000000;">&#40;</span>UITableView tableView, NSIndexPath indexPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
		<span style="color: #FF0000;">string</span> selectedWord <span style="color: #008000;">=</span> parentView.<span style="color: #0000FF;">TableDataSource</span>.<span style="color: #0000FF;">GetAt</span><span style="color: #000000;">&#40;</span>indexPath.<span style="color: #0000FF;">Row</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var alert <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UIAlertView <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Selected&quot;</span>, selectedWord, <span style="color: #0600FF;">null</span>, <span style="color: #666666;">&quot;OK&quot;</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			alert.<span style="color: #0000FF;">Show</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ViewDidLoad <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">ViewDidLoad</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        TableView.<span style="color: #FF0000;">Delegate</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TableDelegate <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TableDataSource</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WordsDataSource <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>MonoTouch.<span style="color: #0000FF;">Foundation</span>.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WordSearchDelegate&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> WordSearchDelegate <span style="color: #008000;">:</span> UISearchDisplayDelegate
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> ShouldReloadForSearchString <span style="color: #000000;">&#40;</span>UISearchDisplayController controller, <span style="color: #FF0000;">string</span> forSearchString<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		UITableViewDataSource data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WordsDataSource<span style="color: #000000;">&#40;</span>forSearchString<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		controller.<span style="color: #0000FF;">SearchResultsDataSource</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I&#8217;m pretty happy with what I got by now. You can <a href="http://lsd.luminis.nl/wp-content/uploads/2009/11/SearchProblems3.zip">download the new version</a>, if you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.eu/en/building-iphone-applications-using-monotouch-part-5-software-design-considerations/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

