<?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>Francois Faubert &#187; OOP</title>
	<atom:link href="http://www.francoisfaubert.com/tag/oop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.francoisfaubert.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 Sep 2009 19:00:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>OOP Javascript</title>
		<link>http://www.francoisfaubert.com/2008/02/10/oop-javascript/</link>
		<comments>http://www.francoisfaubert.com/2008/02/10/oop-javascript/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 20:53:58 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Threads]]></category>

		<guid isPermaLink="false">http://www.francoisfaubert.com/2008/02/10/oop-javascript/</guid>
		<description><![CDATA[If you&#8217;re anything like me, hardcore object-oriented Javascript coding always come with unexpected errors and some of the strangest behavior you can&#8217;t really explain.
But that&#8217;s always the programmer&#8217;s fault, of course. It turns out Javascript isn&#8217;t made to be used in a object-oriented way, but rather in a prototype-oriented fashion.
This lengthy post compares Java and [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re anything like me, hardcore object-oriented Javascript coding always come with unexpected errors and some of the strangest behavior you can&#8217;t really explain.</p>
<p>But that&#8217;s always the programmer&#8217;s fault, of course. It turns out Javascript isn&#8217;t made to be used in a object-oriented way, but rather in a prototype-oriented fashion.</p>
<p><a href="http://peter.michaux.ca/article/5004">This lengthy post</a> compares Java and Javascript and explains how a Javascript programmer should implement object inheritance.</p>
<p>I found a few things strikingly useful in there, notably the delegation of the whole <code>obj.prototype</code> reference and the fact he never explicitly declares any class attributes as he does in Java (and how I was trained to do it).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2008/02/10/oop-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eureka Follow up</title>
		<link>http://www.francoisfaubert.com/2006/02/07/eureka-follow-up/</link>
		<comments>http://www.francoisfaubert.com/2006/02/07/eureka-follow-up/#comments</comments>
		<pubDate>Tue, 07 Feb 2006 16:38:19 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Event Delegation]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://themusictank.com/fake/?p=12</guid>
		<description><![CDATA[The use of a static method to delegate events in Flash is one of the easiest ways of associating functions to an event.]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my last post, the Delegate class is quite useful even if I couldn&#8217;t pass parameters as easily as I would have wanted. While looking around today, I stumbled on <a href="http://www.person13.com/articles/proxy/Proxy.htm">this method</a> which also makes things much easier. I don&#8217;t like how it&#8217;s written because of the in-line functions, but it really does solve the problem. Here&#8217;s the code, which I took the liberty to customize a little bit:</p>
<pre><code>class Utils {
// Desc		:	Usually, when you attach a function to an event, you can't pass
//			parameters, using this function instead of the Delegate class
//			will allow you to do the same thing but with unlimitted parameters
// 			Window: General Information.
// 			http://www.person13.com/articles/proxy/Proxy.htm
public static function delegateEvent(oTarget:Object, fFunction:Function):Function {
    // Create an array of the extra parameters passed to the method. Loop
    // through every element of the arguments array starting with index 2,
    // and add the element to the aParameters array.
    var aParameters:Array = new Array();
    for(var i:Number = 2; i &lt; arguments.length; i++) {
        aParameters[i - 2] = arguments[i];
    }
    // Create a new function that will be the proxy function.
    var fProxy:Function = function():Void {
        var aActualParameters:Array = arguments.concat(aParameters);
        fFunction.apply(oTarget, aActualParameters);
    };
    return fProxy;
}</code></pre>
<p>And you can call it like this:</p>
<pre><code>private function someFunction():Void {
    this._xml.onLoad = Utils.delegateEvent(this, xml_onLoad, "GeneralInformation");
}

private function xml_onLoad(success:Boolean, nextStep:String):Void {
    if(success)
    // Get the contents of xml
    switch (nextStep) {
        case "GeneralInformation" :
            this.open_GeneralInformation(); break;
    //etc...
    }
}</code></pre>
<p>This was a huge time savor and suits how I like to write code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2006/02/07/eureka-follow-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eureka!</title>
		<link>http://www.francoisfaubert.com/2006/02/01/eureka/</link>
		<comments>http://www.francoisfaubert.com/2006/02/01/eureka/#comments</comments>
		<pubDate>Wed, 01 Feb 2006 19:13:52 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Event Delegation]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://themusictank.com/fake/?p=11</guid>
		<description><![CDATA[I’ve been having a lot of trouble having Event (clicks, loads, etc&#8230;) in Flash for as long as I’ve been doing Object-Oriented ActionScript. I barely managed to call inline functions and having to use the absolute path to the property. Example:
class Foo {
	public var _someProperty:String
	public function Foo() {
		// Lets skip how I actually make the [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been having a lot of trouble having Event (clicks, loads, etc&#8230;) in Flash for as long as I’ve been doing Object-Oriented ActionScript. I barely managed to call inline functions and having to use the absolute path to the property. Example:</p>
<pre><code>class Foo {
	public var _someProperty:String
	public function Foo() {
		// Lets skip how I actually make the button,
		// but I usually use .attach() and I make
		// exportable the object in the Library. I
		// think I should use createClassComponent however.
		var but:MovieClip = new MovieClip();
		but.onPress = function () {
		_root.MyFooObject._someProperty = “Clicked”;
		}
	}
}</code></pre>
<p>To access my attribute, I must leave my class and follow the absolute, practically hard-coded, path to my value. It&#8217;s really not a good thing to do. Instead, I found you can use the Delegate class to forward events to a function inside the parent class. Like this:</p>
<pre><code>class Foo {
	private var _someProperty:String
	public function Foo() {
		// Lets skip how I actually make the button here too.
		var but:MovieClip = new movieclip();
		but.onPress = mx.utils.Delegate.create(this, button_onClick);
	}
	private function button_onClick():Void {
		this._someProperty = “Clicked”;
	}
}</code></pre>
<p>Where &#8220;this&#8221; means the class you are in (could be another one), and &#8220;button_onClick&#8221; is the name of the function you will be calling after the event is triggered.</p>
<p>There you go! It’s a lot more powerful, much more logical from a semantic point of view and it makes the code a lot clearer. Notice how I can protect my call properties now using the private attribute.</p>
<p>Speaking of being semantic, you always should call you call properties with &#8220;getters and setters&#8221; instead of calling it directly like I did in my example. It should look like this instead:</p>
<pre><code>private var _someProperty:String
public function get someProperty():String { return this._someProperty;}
public function set someProperty(val:String):Void {
    // validation if needed; this._someProperty = val;
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2006/02/01/eureka/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Love/hate relationship with Flash&#8217;s components</title>
		<link>http://www.francoisfaubert.com/2005/11/12/lovehate-relationship-with-flash%e2%80%99s-components/</link>
		<comments>http://www.francoisfaubert.com/2005/11/12/lovehate-relationship-with-flash%e2%80%99s-components/#comments</comments>
		<pubDate>Sat, 12 Nov 2005 15:11:20 +0000</pubDate>
		<dc:creator>francoisfaubert</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://themusictank.com/fake/?p=5</guid>
		<description><![CDATA[Macromedia have brought a lot more depth into Flash by adding pre-compiled components (or movie clips) to the software&#8217;s library. Mostly available only in the professional edition, these components make building application faster and easier.
One of the components I&#8217;ve played with it the Window object. It&#8217;s simple to understand and it&#8217;s possible to create a [...]]]></description>
			<content:encoded><![CDATA[<p>Macromedia have brought a lot more depth into Flash by adding pre-compiled components (or movie clips) to the software&#8217;s library. Mostly available only in the professional edition, these components make building application faster and easier.</p>
<p>One of the components I&#8217;ve played with it the Window object. It&#8217;s simple to understand and it&#8217;s possible to create a Window on the fly using ActionScript only. Let me put some emphasis on that. Within a few lines, I was able to program my way into a graphic application. We can all agree that&#8217;s the goal behind the general direction Macromedia is taking and to a certain extent they are succeeding in doing so.</p>
<p>However, other components are much harder to instantiate or create/call straight from ActionScript. The documentation on Live Docs is also somewhat deficient. I&#8217;ve tried a gazillion times to have the XML connector work when created dynamically but couldn&#8217;t make it work yet. The media playback was a bit easier to build with dynamic values, but as I write this, the Mp3 player on The Music Tank still has trouble opening .mp3 files consistently.</p>
<p>What I hate about components is how I never know if it&#8217;s my fault if it&#8217;s not working. If it is (which is probably the case) there are two questions I can rarely find answers for:</p>
<ul>
<li>Am I supplying invalid values which failed validation once the control is speaking with my website? And</li>
<li> Is the control not working because I instantiated its properties with wrong values?</li>
</ul>
<p>I hope Flex will make it easier for graphic artists who are able to do real Object-Oriented programming. Right now, I feel pretty dumb having to use illogical code just to make up for Flash&#8217;s &#8220;almost-there&#8221; programming language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.francoisfaubert.com/2005/11/12/lovehate-relationship-with-flash%e2%80%99s-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
