<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>design-nation.blog/en</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/" />
    <link rel="self" type="application/atom+xml" href="http://www.design-nation.net/en/atom.xml" />
   <id>tag:www.design-nation.net,2007:/en//4</id>
    <link rel="service.post" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4" title="design-nation.blog/en" />
    <updated>2007-01-20T12:55:22Z</updated>
    <subtitle>a blog about actionscript, java, cocoa and software development in general</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 3.2</generator>
 
<entry>
    <title>Flash Lite or J2ME?</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002161.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2161" title="Flash Lite or J2ME?" />
    <id>tag:ctarda.dreamhosters.com,2006:/en//4.2161</id>
    
    <published>2006-01-03T11:24:30Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>Almost a year ago, I posted a comparison between Flash Lite and J2ME. As you probably now, the Flash Lite 2 update for Flash Professional 8 has just been released through Macromedia Labs, and it’s time to rewrite that post....</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="FlashLite" />
            <category term="J2ME" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>Almost a year ago, <a href="http://www.design-nation.net/en/archives/000453.php">I posted a comparison between Flash Lite and J2ME</a>.</p>

<p>As you probably now, the <a href="http://labs.macromedia.com/technologies/flashlite2_update_flashpro8/">Flash Lite 2 update for Flash Professional 8</a> has just been released through Macromedia Labs, and it’s time to rewrite that post.</p>]]>
        <![CDATA[<p>Has there been any change?</p>

<p>Thankfully, yes!. While the J2ME platform has been slowly but safely following its well established path, adding a few new profiles, the release of Flash Lite 2 brings a lot joy and good news for mobile developers.</p>

<p>So, what’s new in Flash Lite 2?<br />
Maybe the most important improvement in the new player is the support for ActionScript 2.0. So, we can forget about one the most important caveats of the old Flash Lite player, which was the flash 4 syntax (which also meant complex nested movieclips structures, code everywhere, and a deprecated syntax).</p>

<p>Now we don’t have to jump between two different syntaxes, and we don’t have to jump between two different development paradigms. We finally have an object-oriented language, with all its advantages: code reuse, small entities that are responsible of small tasks,... well, you know.</p>

<p>But the adoption of AS2 is not only an advantage by itself. Been able to develop a desktop application, a web application or a Flash Lite application writing exactly the same code will make much easier for all the developers out there to try the technology. And more developers working on "the shinny thing" means more applications available, and having more applications available will mean that there will be a stronger demand for more good applications. So, everybody wins.</p>

<p>Yeah, AS2, cool, but isn’t there anything else?</p>

<p>Yes, there are two more things, that, from my point of view, will make Flash Lite a serious J2ME contender: local storage and XML support. Why?</p>

<p>Local storage support is probably the most important feature of Flash Lite 2. GPS connections are expensive (here is Spain, are obscenely expensive, so you can imagine the cost of a 3G connection), so the users must be able to store small chunks of data in their devices. Period. This was something that was needed, and that Macromedia has implemented, so we can only be thankful for it. </p>

<p>But when there’s the need of downloading complex data, the old loadmovie command was a real pain. We asked for it, and now we have it. Cool.</p>

<p>So, one of the weaker points of Flash Lite, which was the lack of functionality, is not so important right now. Of course, there are many things you can do when developing a J2ME application, like accessing the Bluetooth or the PIM or the camera api, but in most applications there will not be the need to do so. I mean, how many mobile apps are multiuser Bluetooth-driven games?. Not so many.</p>

<p>So, there’s still a certain lack of functionality, but, from my point of view, it’s not such an important point as it was before.</p>

<p>Conclusion</p>

<p>J2ME is almost in the same point where it was a year ago. Flash Lite isn’t, and now, more than ever, I feel that, before starting to develop a new application, I can really stop and think about what’s the best tool for the job, if it’s Flash Lite or if it’s J2ME, because, right now I am not only constrained to J2ME. </p>

<p>I finally can choose.</p>]]>
    </content>
</entry>
<entry>
    <title>FlashLite player 2 is available</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002160.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2160" title="FlashLite player 2 is available" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2160</id>
    
    <published>2005-12-21T15:03:59Z</published>
    <updated>2007-01-20T20:46:55Z</updated>
    
    <summary>I&apos;m sure you have read in the aggregators, but I won&apos;t do any harm to read about it once again. FlashLite 2 player is available through the la Adobe online store, and it costs 8 € (ex. VAT). There is...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="FlashLite" />
            <category term="J2ME" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>I'm sure you have read in the aggregators, but I won't do any harm to read about it once again.</p>

<p>FlashLite 2 player is available through the <a href="http://www.macromedia.com/cfusion/store/index.cfm?store=OLS-EU&view=ols_prod&category=/Software/Development/StandAlones/FlashLite2">la Adobe online store</a>, and it costs 8 € (ex. VAT).</p>

<p>There is no official documentation yet, and it is not possible to start developing specific content, but at least we can start testing our old FlashLite 1.1 apps against the new player ;)</p>

<p>You can read more about the announcement <a href="http://www.flashdevices.net/2005/12/flash-lite-player-2-now-available.html">at Flash Devices</a>.</p>

<p>Enjoy your new toy...</p>]]>
        
    </content>
</entry>
<entry>
    <title>Business &amp; marketing for the Mac Developer</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002159.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2159" title="Business &amp; marketing for the Mac Developer" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2159</id>
    
    <published>2005-12-12T08:53:01Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>The Apple Developer Connection website has added a new section that provides, among other useful tips, a collection of Business &amp; Marketing Frequently Asked Questions, information about specific markets (like education, science &amp; technology...). I think it&apos;s worth a read...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Cocoa" />
            <category term="Java" />
            <category term="Mac" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>The <a href="http://developer.apple.com/">Apple Developer Connection</a> website has added a new section that provides, among other useful tips, a collection of Business & Marketing Frequently Asked Questions, information about specific markets (like education, science & technology...).</p>

<p>I think it's worth a read if you are a Mac developer.</p>

<p><a href="http://developer.apple.com/business/index.html">Business & Marketing for the Mac Developer</a></p>]]>
        
    </content>
</entry>
<entry>
    <title>How to write unmaintenable code</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002158.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2158" title="How to write unmaintenable code" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2158</id>
    
    <published>2005-11-26T07:53:33Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>And old link, that I lost, and that I found again yesterday. I love the opening quote: &quot; Never ascribe to malice, that which can be explained by incompetence&quot; A funny read: how to write unmaintenable code...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Flash-ActionScript" />
            <category term="General" />
            <category term="Java" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>And old link, that I lost, and that I found again yesterday. I love the opening quote: <i>" Never ascribe to malice, that which can be explained by incompetence"</i></p>

<p>A funny read: <a href="http://thc.org/root/phun/unmaintain.html">how to write unmaintenable code</a></p>]]>
        
    </content>
</entry>
<entry>
    <title>[Cocoa] Memory management and exceptions</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002157.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2157" title="[Cocoa] Memory management and exceptions" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2157</id>
    
    <published>2005-11-23T16:55:10Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>In languages like Java and actionscript, the &quot;runtime&quot; manages memory, using what is called a garbage collector, that reclaims the memory occupied by an object once it determines that object is no longer accessible. In Objective-C, the programmer must release the resources that he or she has previously allocated to be used by the program.

Memory management is not difficult by itself, because the developer must follow only a few rules, but it is the source of many memory leaks, specially when the program behaves in an unexpected way.

So, what happens when we need to throw exceptions?. How can we be sure that we are not producing memory leaks?. Chris Hanson writes about it in Cocoa memory management &amp; exceptions</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Cocoa" />
            <category term="Flash-ActionScript" />
            <category term="Java" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>In languages like Java and actionscript, the "runtime" manages memory, using what is called a garbage collector, that reclaims the memory occupied by an object once it determines that object is no longer accessible. In Objective-C, the programmer must release the resources that he or she has previously allocated to be used by the program.</p>

<p>Memory management is not difficult by itself, because the developer must follow only a few rules, but it is the source of many memory leaks, specially when the program behaves in an unexpected way.</p>

<p>So, what happens when we need to throw exceptions?. How can we be sure that we are not producing memory leaks?. Chris Hanson writes about it in <a href="http://www.livejournal.com/users/chanson/126035.html">Cocoa memory management & exceptions</a></p>]]>
        
    </content>
</entry>
<entry>
    <title>Tomorrow in the papers</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002156.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2156" title="Tomorrow in the papers" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2156</id>
    
    <published>2005-11-03T22:29:23Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>design-nation is in the papers. In the October&apos;s issue of MacWorld Spain, there is an articles written by me, the First Contact with Macromedia Studio 8. Even with that article, the magazine is full of interesting contents, like a report...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Flash-ActionScript" />
            <category term="General" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>design-nation is in the papers. In the October's issue of <a href="http://www.macworld.es">MacWorld Spain</a>, there is an articles written by me, the First Contact with Macromedia Studio 8.</p>

<p>Even with that article, the magazine is full of interesting contents, like a report about the .Mac services, an in-depth article about iMovieHD or a comparison between all the Macs.</p>

<p>If you can read Spanish, you should buy it...</p>]]>
        
    </content>
</entry>
<entry>
    <title>Design patterns poster</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002155.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2155" title="Design patterns poster" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2155</id>
    
    <published>2005-11-01T18:12:55Z</published>
    <updated>2007-01-20T12:54:58Z</updated>
    
    <summary>I am sure you have heard about the Head First series and about the Head First Design Patterns book, because it is probably the best introductory book to understand design patterns. Last week I was browsing amazon when I found...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Design Patterns" />
            <category term="Flash-ActionScript" />
            <category term="J2ME" />
            <category term="Java" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>I am sure you have heard about the Head First series and about the <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0596007124/qid=1130864263/sr=8-1/ref=sr_8_xs_ap_i1_xgl/202-7220919-6724630">Head First Design Patterns</a> book, because it is probably the best introductory book to <i>understand</i> design patterns.</p>

<p>Last week I was browsing amazon when I found this item: <a href="http://www.amazon.co.uk/exec/obidos/ASIN/0596102143/qid=1130864263/sr=8-2/ref=sr_8_xs_ap_i2_xgl/202-7220919-6724630">Head First Design Patterns Poster</a>.</p>

<p><img src="http://www.design-nation.net/en//archives/designPatternsPoster.jpg" border="0" height="399" width="414" alt="designPatternsPoster.jpg" align="" /></p>

<p>As its name says, it is a poster (a big one, in fact) that contains a graph (taken from the original book), not an UML diagram but a graph that explains the pattern and also the page number of the pattern in both the Gang of four and Head First Design Patterns.</p>

<p>It visually summarizes 18 patterns, and it is attached to the wall in front of my computer right now...</p>

<p>(By the way, all the links in this post will NOT earn me a comission).</p>]]>
        
    </content>
</entry>
<entry>
    <title>And the pattern was...</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002154.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2154" title="And the pattern was..." />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2154</id>
    
    <published>2005-10-18T08:42:19Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>Strategy. That was the name of the pattern in yesterday&apos;s post....</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Design Patterns" />
            <category term="Flash-ActionScript" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>Strategy. That was the name of the pattern in <a href="http://www.design-nation.net/en/archives/000886.php">yesterday's post</a>.</p>]]>
        
    </content>
</entry>
<entry>
    <title>An example of the guess-its-name pattern</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002153.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2153" title="An example of the guess-its-name pattern" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2153</id>
    
    <published>2005-10-17T07:26:57Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>Professor Coupling has been enjoying his well deserved hollidays after conquering the world (yes, since the last time we knew about him he seems to have succeeded with his evil plan).

But ruling the world is quite boring. Professor Coupling misses the old times, when nobody understood him, when he could hate all the world&apos;s leaders because they ignored him... Now he has to deal with a lot of paperwork everyday, and he misses when he could hang around with his troops, telling jokes, and drinking beer.

So, he has decided that, to combat this mortal boredom, he wants to see a millitary parade everyday. A different parade everyday, formed by a different selection from his troops. One day he will ask his Marshal to form a parade with the cows from the company B, another day he will want a parade formed by all the sheeps whose name contains an &quot;a&quot;... Evil geniuses...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Design Patterns" />
            <category term="Flash-ActionScript" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>UPDATED: This is the Strategy Pattern. So, the title of the post could be "An example of the strategy pattern in actionscript"</p>

<p>Professor Coupling has been enjoying his well deserved hollidays after conquering the world (yes, since the last time we knew about him he seems to have succeeded with his evil plan).</p>

<p>But ruling the world is quite boring. Professor Coupling misses the old times, when nobody understood him, when he could hate all the world's leaders because they ignored him... Now he has to deal with a lot of paperwork everyday, and he misses when he could hang around with his troops, telling jokes, and drinking beer.</p>

<p>So, he has decided that, to combat this mortal boredom, he wants to see a millitary parade everyday. A different parade everyday, formed by a different selection from his troops. One day he will ask his Marshal to form a parade with the cows from the company B, another day he will want a parade formed by all the sheeps whose name contains an "a"... Evil geniuses...</p>]]>
        <![CDATA[<p>Professor Coupling troops are well trained. They know that, when asked for their names all they can say is their name, company, and serial number. Nothing more. So think of a solider as something like this:</p>

<code language="actionScript">
class Soldier
{
private var name	: String;
private var id		: String;
private var company	: String;
private var weapons	: Object;
	
function Soldier( initInfo: Object )
{
this.name 	= initInfo.name;
this.id		= initInfo.id;
this.company= initInfo.company;
}
	
public function getPublicInfo( )
{
return { name: this.name, id: this.id, company: this.company };
}
	
//Other methods
	
public function toString( ): String
{
return "soldier{ name: " + this.name + ", id: " + this.id + ", company: " + this.company + " }";
}
}
</code>

<p>What defines a soldier is its name, its company, and its serial number (id), and that is the info they will provide when asked.</p>

<p>So, imagine that professor coupling asks his Marshal to prepare a parade with all the soldiers from company B. The Marshal, whose responsibility is to build and maintain an army, will have to go asking all his soldiers for their company, and select only those that serve in the company B. But now, imagine that Professor Coupling wants a parade formed by all the soldiers whose name contains a "P". The Marshal will have to loop through all his soldiers, and select only those whose name contains a "P". So, the Marshal code will be something like this:</p>

<code language="actionScript">
class Marshal
{
public static var CONTAINS_LETTER: String = "Letter";
public static var COMPANY		: String = "Company";
	
private var soldiersList: Array;
	
function Marshal( )
{
this.soldiersList = new Array( );
}
	
public function recruitSoldier( newSoldier: Soldier )
{
this.soldiersList.push( newSoldier );
}
	
public function getFilteredCollection( filterType: String, filterValue: String ): Array
{
var returnVal: Array = new Array( );
var numSoldiers: Number = this.soldiersList.length;
		
var actualSoldierInfo: Object;
		
for( var k: Number = 0; k< numSoldiers; k++ )
{
actualSoldierInfo = this.soldiersList[ k ].getPublicInfo( ); 
			
switch( filterType )
{
case Marshal.CONTAINS_LETTER:
if( actualSoldierInfo.name.indexOf( filterValue ) != -1 )
{
returnVal.push( this.soldiersList[ k ] );
}
					
break;
				
case Marshal.COMPANY:
if( actualSoldierInfo.company == filterValue )
{
returnVal.push( this.soldiersList[ k ] );
}
			
break;
				
default:
trace( "Filter not created" );
}
}
return returnVal;
}
}
</code>

<p>So Professor Coupling will do something like:</p>

<code language="actionScript">
class Professor
{
function Professor( )
{
		
}
	
public static function initApp( )
{
var professor	: Professor = new Professor( );
var marshal	: Marshal 	= new Marshal( );
		
marshal.recruitSoldier( new Soldier( { name: "Peter",	id: "0001", company: "B" } ) );
												
marshal.recruitSoldier( new Soldier( { name: "Paul",	id: "0002", company: "B" } ) );		
marshal.recruitSoldier( new Soldier( { name: "Cesar",	id: "0003", company: "A" } ) );	
marshal.recruitSoldier( new Soldier( { name: "Javier",	id: "0004", company: "B" } ) );
												
var companyB: Array 	= marshal.getFilteredCollection( Marshal.COMPANY, "B" );
trace( companyB );
		
var companyA: Array 	= marshal.getFilteredCollection( Marshal.COMPANY, "A" );
trace( companyA );
		
var nameWithP: Array 	= marshal.getFilteredCollection( Marshal.CONTAINS_LETTER, "P" );
trace( nameWithP );
		
var nameWithe: Array 	= marshal.getFilteredCollection( Marshal.CONTAINS_LETTER, "e" );
trace( nameWithe );

}
}
</code>

<p>But what happens if now, Professor Coupling wants a parade formed with the soldiers whose id is lower than a given number. The code of the Marshal class will have to be changed. And what if now, Professor Coupling wants... (you, know, this always happens with evil geniuses, they always want more...). The code of the Marshal class can not be easily scaled. It is not easy to add new filtering conditions. But there is also another problem. With every iteration of the loop, all the possible conditions have to be checked, which is, to say the least, not too elegant. And Professor Coupling can be crazy, but he is not an idiot, and he wants his code to be clean, easy to maintain, and elegant.
So, he remembers (insert thunders, laughs, and melodramatic music here, please) when he was a student, and he learnt about the (sorry, naming it is up to you) pattern.</p>

<p>If he finds the way to give his Marshal a package containing the condition to check, in a way that the Marshal doesn't need to know what he is checking, the problem will be solved. The Marshal should delegate the condition checking in what Professor Coupling gives him, and new conditions could be added without changing the Marshal code. Let's see how.</p>

<p>Professor Coupling will, then, give the Marshal a class that will be responsible for checking the filtering condition. But there can be many conditions, so all of them should have a common interface, so the Marshal could interact with them in an anonymous way.</p>

<p>This interface could be:</p>
<code language="actionScript">
interface ICompare
{
public function matches( checkValues: Object ): Boolean;
}
</code>

<p>So, one condition could be:</p>

<code language="actionScript">
class NameContainsLetterFilter implements ICompare
{
private var refValue: String;
	
function NameContainsLetterFilter( ref: String )
{
this.refValue = ref;
}
	
public function matches( checkValues: Object ): Boolean
{
return ( checkValues.name.indexOf( this.refValue ) != -1 );
}
}
</code>

<p>And the Marshal code will be:</p>

<code language="actionScript">
class Marshal
{
private var soldiersList: Array;
	
function Marshal( )
{
this.soldiersList = new Array( );
}
	
public function recruitSoldier( newSoldier: Soldier )
{
this.soldiersList.push( newSoldier );
}
	
public function getFilteredCollection( filter: ICompare ): Array
{
var returnVal: Array = new Array( );
var numSoldiers: Number = this.soldiersList.length;
		
var actualSoldierInfo: Object;
		
for( var k: Number = 0; k< numSoldiers; k++ )
{
actualSoldierInfo = this.soldiersList[ k ].getPublicInfo( ); 
			
if( filter.matches( actualSoldierInfo ) )
{
returnVal.push( this.soldiersList[ k ] );
}
}
return returnVal;
}
}
</code>

<p>And Professor Coupling will do something like:</p>

<code language="actionScript">
class Professor
{
function Professor( )
{
		
}
	
public static function initApp( )
{
var professor	: Professor = new Professor( );
var marshal		: Marshal 	= new Marshal( );
		
marshal.recruitSoldier( new Soldier( { name: "Peter",	id: "0001", company: "B" } ) );
												
marshal.recruitSoldier( new Soldier( { name: "Paul",   id: "0002", company: "B" } ) );		
marshal.recruitSoldier( new Soldier( { name: "Cesar",	id: "0003", company: "A" } ) );	
marshal.recruitSoldier( new Soldier( { name: "Javier",	id: "0004", company: "B" } ) );
												
var nameWithP: Array 	= marshal.getFilteredCollection( new NameContainsLetterFilter( "P" ) );
trace( nameWithP );
		
var nameWithe: Array 	= marshal.getFilteredCollection( new NameContainsLetterFilter( "e" ) );
trace( nameWithe );
		
}
}
</code>

<p>Adding new filters will be easy. To add a filter by the name of the company, Professor Coupling will have to encapsulate it in a class:</p>

<code language="actionScript">
class CompanyFilter implements ICompare
{
var refValue: String;
	
public function CompanyFilter( ref: String )
{
this.refValue = ref;
}
	
public function matches( checkValues: Object ): Boolean
{
return ( checkValues.company == this.refValue );
}
}
</code>

<p>Another filter:</p>

<code language="actionScript">
class IDLowerFilter implements ICompare
{
private var refValue: String
	
function IDLowerFilter( ref: String )
{
this.refValue = ref;
}
	
public function matches( checkValues: Object ): Boolean
{
var ref		: Number = parseInt( this.refValue, 10 );
var check	: Number = parseInt( checkValues.id, 10 );
		
return ( check<= ref );
}
}
</code>
<p>So, to use those filters:</p>

<code language="actionScript">
class Professor
{
function Professor( )
{
		
}
	
public static function initApp( )
{
var professor	: Professor = new Professor( );
var marshal		: Marshal 	= new Marshal( );
		
marshal.recruitSoldier( new Soldier( { name: "Peter",	id: "0001", company: "B" } ) );
												
marshal.recruitSoldier( new Soldier( { name: "Paul",   id: "0002", company: "B" } ) );		
marshal.recruitSoldier( new Soldier( { name: "Cesar",	id: "0003", company: "A" } ) );	
marshal.recruitSoldier( new Soldier( { name: "Javier",	id: "0004", company: "B" } ) );
												
var nameWithP: Array 	= marshal.getFilteredCollection( new NameContainsLetterFilter( "P" ) );
trace( nameWithP );
		
var nameWithe: Array 	= marshal.getFilteredCollection( new NameContainsLetterFilter( "e" ) );
trace( nameWithe );

var companyB: Array 	= marshal.getFilteredCollection( new CompanyFilter( "B" ) );
trace( companyB );
		
var companyA: Array 	= marshal.getFilteredCollection( new CompanyFilter( "A" ) );
trace( companyA );

var idLessThan2: Array 	= marshal.getFilteredCollection( new IDLowerFilter( "0002" ) );
trace( idLessThan2 );
		
var idLessThan3: Array 	= marshal.getFilteredCollection( new IDLowerFilter( "0003" ) );
trace( idLessThan3 );		
}
}
</code>

<p>So, Professor Coupling has been able to change the filters without changin the Marshal code.
Now, some considerations. All the filters implement the same interface. You could say "Well, why don't they just extend a base class?". Sure, they could, but imagine that the reference value is a Number instead of a String, or that there are two reference values in a given filter, or... That's why they just implement an interface (altough in this example it will be valid to make them extend a base class).</p>

<p>Then, what has Professor Coupling done?. First, he has followed the <a href="http://www.eventhelix.com/RealtimeMantra/Object_Oriented/open_closed_principle.htm">open-closed principle</a>. The Marshal is open for extensions but closed for modifications. That means that his functionality can be extended without changing its code.</p>

<p>Second, he has delegated the construction of the filters in an entity different to the one that executes them. So the creation of those filters is totally decoupled.</p>

<p>But, the pattern can be improved. A filter could be created composing it from two or more existing filters, for instance. But that will be another Professor Coupling adventure...</p>

<p>Now, it's time for you to guess the name of the pattern... *hint* Professor Coupling has decoupled an algorithm from its host, encapsulating it in a separate class.</p>

<p><a href="http://www.design-nation.net/en/archives/strategy.zip">Download the source code</a>. (if you wish, of course)</p>]]>
    </content>
</entry>
<entry>
    <title>[Cocoa] Some links</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002152.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2152" title="[Cocoa] Some links" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2152</id>
    
    <published>2005-10-16T22:01:48Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>In the last weeks there have been some interesting posts about Cocoa. In Theobroma Cacao, Scott Stevenson has posted two articles about key-value coding: Key-Value Coding (KVC) and Generic Programming NSArray and KVC In Mac Geekery, codepoet has posted two...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Cocoa" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>In the last weeks there have been some interesting posts about Cocoa. In <a href="http://theocacao.com/">Theobroma Cacao</a>, Scott Stevenson has posted two articles about key-value coding:</p>

<ul>
<li><a href="http://theocacao.com/document.page/161">Key-Value Coding (KVC) and Generic Programming</a></li>
<li><a href="http://theocacao.com/document.page/165">NSArray and KVC</a></li>
</ul>

<p>In <a href="http://www.macgeekery.com">Mac Geekery</a>, <a href="http://www.codepoetry.net/">codepoet</a> has posted two tutorials about Core Data:</p>

<ul>
<li><a href="http://www.macgeekery.com/gspot/2005-40/core_data_as_a_cheap_database">Core Data as a Cheap Database</a></li>
<li><a href="http://www.macgeekery.com/development/multiple_entities_in_a_core_data_database">Multiple Entities in a Core Data Database</a></li>
</ul>]]>
        
    </content>
</entry>
<entry>
    <title>[Cocoa] Introduction to memory management</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002151.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2151" title="[Cocoa] Introduction to memory management" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2151</id>
    
    <published>2005-10-09T17:56:06Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>Informit published an article a few days ago about memory management in Cocoa, called A Java Programmer&apos;s Introduction to Objective-C: Memory Management. The article focuses on the differences between Java and Cocoa regarding memory management, and it can be useful...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Cocoa" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>Informit published an article a few days ago about memory management in Cocoa, called <i><a href="http://www.informit.com/articles/article.asp?p=377302&rl=1">A Java Programmer's Introduction to Objective-C: Memory Management</a></i>.</p>

<p>The article focuses on the differences between Java and Cocoa regarding memory management, and it can be useful as an introduction to the most important, powerful and complex aspect of Objective-C, which is the lack of a garbage collector.</p>

<p><a href="http://www.informit.com/articles/article.asp?p=377302&rl=1">A Java Programmer's Introduction to Objective-C: Memory Management</a></p>]]>
        
    </content>
</entry>
<entry>
    <title>[J2ME] Netbeans Mobility Pack 5.0 beta</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002150.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2150" title="[J2ME] Netbeans Mobility Pack 5.0 beta" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2150</id>
    
    <published>2005-09-29T10:28:18Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>Yesterday was a busy day at NetBeans. Not only they have released NetBeans 5.0 beta, but also Mobility Pack 5.0 beta At first glance, there are some new features that will make our life a bit easier: JSR 172 (...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="J2ME" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>Yesterday was a busy day at NetBeans. Not only they have released <a href="http://www.netbeans.org/downloads/index.html">NetBeans 5.0 beta</a>, but also  <a href="http://www.netbeans.org/kb/50/mobility.html">Mobility Pack 5.0 beta</a></p>

<p>At first glance, there are some new features that will make our life a bit easier: JSR 172 ( webservices ) support, improved UI designer, and improved support for emulators.</p>

<p>More information and downloads here: <a href="http://www.netbeans.org/kb/50/mobility.html">Java ME MIDP Development for NetBeans IDE 5.0</a></p>]]>
        
    </content>
</entry>
<entry>
    <title>[J2ME] Some articles of interest</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002149.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2149" title="[J2ME] Some articles of interest" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2149</id>
    
    <published>2005-09-29T00:14:05Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>Sony-Ericsson&apos;s Developer World has published the third article in a series about 3D programming. This is new article is about programming particle systems Here are the links to the three articles: 3D programming tutorial for mobile devices using M3G 3D...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="J2ME" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>Sony-Ericsson's Developer World has published the third article in a series about 3D programming. This is new article is about programming particle systems </p>

<p>Here are the links to the three articles:</p>

<ul>
<li><a href="http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/mobilejava3d/p_java3d_tutorial_part1_compliments_redikod.jsp?link_techtips=java3d-redikodtutorialpart1">3D programming tutorial for mobile devices using M3G</a></li>
<li><a href="http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/mobilejava3d/p_java3d_tutorial_part2_compliments_redikod.jsp?link_techtips=java3d-redikodtutorialpart2">3D programming tutotial part two: Light 3D theory and orientation</a></li>
<li><a href="http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/mobilejava3d/p_java3d_tutorial_part3_compliments_redikod.jsp?link_techtips=java3d-redikodtutorialpart3">3d programming tutorial part three: particle systems and immediate mode rendering</a></li>
</ul>

<p>Sun Developer Network has published the second article in a series about ecryption in MIDP</p>

<ul>
<li><a href="http://developers.sun.com/techtopics/mobility/midp/articles/security4/">MIDP Application Scrutiry 4: Encryption in MIDP</a></li>
</ul>]]>
        
    </content>
</entry>
<entry>
    <title>An interesting post about floats</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002148.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2148" title="An interesting post about floats" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2148</id>
    
    <published>2005-09-27T11:18:09Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>Ridiculous_fish has published a very interesting post about floating point numbers. Although it is oriented to explain how things work in the Cocoa world, it brings a lot of useful information about floats. I think it is really worth to...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="General" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p><a href="http://ridiculousfish.com/blog/?p=24">Ridiculous_fish</a> has published a very interesting post about floating point numbers. Although it is oriented to explain how things work in the Cocoa world, it brings a lot of useful information about floats.</p>

<p>I think it is really worth to check it out.</p>

<p><a href="http://ridiculousfish.com/blog/?p=24">Float</a></p>]]>
        
    </content>
</entry>
<entry>
    <title>[Cocoa] Apple launches the ADC Bookshelf</title>
    <link rel="alternate" type="text/html" href="http://www.design-nation.net/en/archives/002147.php" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.design-nation.net/cgi-bin/mt-atom.cgi/weblog/blog_id=4/entry_id=2147" title="[Cocoa] Apple launches the ADC Bookshelf" />
    <id>tag:ctarda.dreamhosters.com,2005:/en//4.2147</id>
    
    <published>2005-09-26T23:33:15Z</published>
    <updated>2007-01-20T12:55:22Z</updated>
    
    <summary>Which is just an Apple-branded Safari Bookshelf, but that promises to be focused on Mac related titles. I am still not sure if I like the idea of buying things that in fact I am just renting instead of buying,...</summary>
    <author>
        <name>Cesar Tardaguila</name>
        <uri>http://www.design-nation.net</uri>
    </author>
            <category term="Cocoa" />
            <category term="Mac" />
    
    <content type="html" xml:lang="en" xml:base="http://www.design-nation.net/en/">
        <![CDATA[<p>Which is just an Apple-branded <a href="http://www.safaribooksonline.com/home.asp">Safari Bookshelf</a>, but that promises to be focused on Mac related titles.</p>

<p>I am still not sure if I like the idea of buying things that in fact I am just renting instead of buying, but...</p>

<p><a href="http://developer.apple.com/adcbookshelf/">ADC bookshelf</a></p>]]>
        
    </content>
</entry>

</feed> 

