<?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>Ghost23 Blog &#187; OOP</title>
	<atom:link href="http://www.ghost23.de/category/oop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghost23.de</link>
	<description>A blog about Flash and stuff</description>
	<lastBuildDate>Fri, 11 Jun 2010 10:13:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The &#8220;&#124;&#124;&#8221; operator and a chain of responsibility</title>
		<link>http://www.ghost23.de/2010/06/the-operator-and-a-chain-of-responsibility/</link>
		<comments>http://www.ghost23.de/2010/06/the-operator-and-a-chain-of-responsibility/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 16:45:52 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[chain of responsibility]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=326</guid>
		<description><![CDATA[Juten Tach, lately i came across the &#124;&#124; operator again and i read through the language specification. Little quiz: What is the content of the variable result in this line of code? var result:* = null &#124;&#124; "one" &#124;&#124; "two"; The answer is: &#8220;one&#8221;. As for me, i had forgotten, that the &#124;&#124; operator actually [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>lately i came across the || operator again and i read through the language specification. Little quiz: What is the content of the variable <em>result</em> in this line of code?</p>
<pre>var result:* = null || "one" || "two";</pre>
<p>The answer is: &#8220;one&#8221;. As for me, i had forgotten, that the || operator actually returns the value, that evaluates to true. If both values evaluate to true it returns the one on the left first.</p>
<p>So i started to think about, how to make use of this and the Chain of Responsibility Pattern came to my mind. You remember this pattern, right? You have a list of classes, that have different capabilities and you have a task. Instead of finding out by yourself, which class to use, you simply pass it to a chain, where these classes are connected. Each class determines for itself, if it is responsible and the first one, that answers with yes, is returned and gets the job.</p>
<p>So here i present a little exemplary implementation of a Chain of Responsibility, that in its core makes use of the || operator. By the way, i am not really conforming to the original pattern, because i actually don&#8217;t like it. In the original pattern, the potentially responsible classes link to each other directly, which in my opinion causes some trouble. First, they have to be aware, that they are part of a chain, which i think, they shouldn&#8217;t and second, they define the order in the chain themselves, which i think they shouldn&#8217;t and third, the requesting class has to know, which one is the first class in the chain, which i think, it shouldn&#8217;t.</p>
<p><strong>[Caution]</strong>: This post now gets a bit lengthy <img src='http://www.ghost23.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To build this Chain Of Responsibility thing, we need four ingredients: a chain, some potentially responsible classes, a request that should be processed and finally a using class, which wants the request to be processed.</p>
<p>We start with the request. For this example, it is really simple:</p>
<pre>package responsibility {
   public class Request {

      public var stuffToBeProcessed:*;
   }
}</pre>
<p>As you can see, there is just a variable, which holds some kind of value, with which we want to work with. I did not give it a type to make it more interesting at runtime. You will see later on.</p>
<p>OK, next we need some classes, which can handle this type of request. Therefore we define an interface, which describes this general ability.</p>
<pre>package responsibility {
   public interface Responsible {

      /**
       * Checks, if this class can handle the request.
       * @return An instance of Responsible or null.
       */
      function checkResponsibility(request:Request):Responsible;

      /**
       * Processes the request.
       */
      function doIt():void;
   }
}</pre>
<p>Pretty easy, right? The <em>checkResponsibility(request:Request)</em> method will either return itself, if it feels responsible for the request or <em>null</em>. The <em>doIt()</em> method then will actually do, whatever is to be done for fulfilling the request.</p>
<p>Next, we have two concrete classes, which implement this interface, ResponsibleOfStrings and ResponsibleOfNumbers:</p>
<pre>package responsibility {
   public class ResponsibleOfStrings implements Responsible {

      public function checkResponsibility(request:Request):Responsible {
         if(request.stuffToBeProcessed is String) {
            return this;
         }else return null;
      }

      public function doIt():void {
         trace("ResponsibleOfStrings is doing it!");
      }
   }
}

package responsibility {
   public class ResponsibleOfNumbers implements Responsible {

      public function checkResponsibility(request:Request):Responsible {
         if(request.stuffToBeProcessed is Number) {
            return this;
         }else return null;
      }

      public function doIt():void {
         trace("ResponsibleOfNumbers is doing it!");
      }
   }
}</pre>
<p>So, you can see, these classes simply check if the request holds a string or a number respectively. If they find what they expect, they return themselves, otherwise they return <em>null</em>.</p>
<p>OK, next we need a chain. Very well, here it is:</p>
<pre>package responsibility {
   public class ChainOfResponsibility {

      private var listOfResponsibleObjects:Vector. = new Vector.;

      public function addResponsibleObject(responsibleObject:Responsible):void {
         listOfResponsibleObjects.push(responsibleObject);
      }

      public function determineResponsibleObject(request:Request):Responsible {

         var result:Responsible = null;

         for(var i:int = 0; i &lt; listOfResponsibleObjects.length; i++) {
            result ||= listOfResponsibleObjects[i].checkResponsibility(request);
         }

         return result;
      }
   }
}</pre>
<p>So finally here comes the part with the || operator. We run a list of potentially responsible classes. And in the function <em>determineResponsibleObject(request:Request)</em>, we now go through this list. And here we make use of the fact, that when we chain the return values of each <em>checkResponsibility(request)</em> call by using the || operator, we get the first one, that returned itself instead of <em>null</em>. Means, we get the first class instance, which feels responsible for doing the job.</p>
<p>OK, lastly of course, we want to see, how to use that stuff. So here it is:</p>
<pre>package {

   import flash.display.Sprite;
   import responsibility.*;

   public class Main extends Sprite {

      public function Main() {

         var chainOfResponsibility:ChainOfResponsibility = new ChainOfResponsibility;
         chainOfResponsibility.addResponsibleObject(new ResponsibleOfNumbers);
         chainOfResponsibility.addResponsibleObject(new ResponsibleOfStrings);

         var request:Request = new Request;
         request.stuffToBeProcessed = 10;

         var responsibleObject:Responsible = chainOfResponsibility.determineResponsibleObject(request);
         responsibleObject.doIt();
      }
   }
}</pre>
<p>So, first we are setting up our Chain of Responsibility an give it our two responsible classes. Then we build a new request. In this case, we assign a number to the variable <em>stuffToBeProcessed</em>. Then we hand that request over to our chain and save the result in our variable <em>responsibleObject</em>. Finally we call the <em>doIt()</em> method on that object. And if we run this, we get a trace saying &#8220;ResponsibleOfNumbers is doing it!&#8221;, as expected. Of course, if we had assigned a string to the variable <em>stuffToBeProcessed</em>, than we would have seen &#8220;ResponsibleOfStrings is doing it!&#8221;.</p>
<p>Well, that&#8217;s it. If you find this useful, you can use it freely for any purpose.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/06/the-operator-and-a-chain-of-responsibility/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 &#8211; feature request filed &#8211; const initialization in constructor</title>
		<link>http://www.ghost23.de/2010/05/as3-feature-request-filed-const-initialization-in-constructor/</link>
		<comments>http://www.ghost23.de/2010/05/as3-feature-request-filed-const-initialization-in-constructor/#comments</comments>
		<pubDate>Sat, 15 May 2010 12:26:14 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[compiler]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=308</guid>
		<description><![CDATA[Juten Tach, i already wrote about this a while ago, but now i have filed a feature request in the bug base of Adobe. I want const fields allow for being initialized in the constructor, too, not only inline. Here&#8217;s, what i wrote in the ticket: hello, in the AS3 specification it says: &#8220;A variable [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>i already wrote <a href="http://www.ghost23.de/2009/03/constants/">about this</a> a while ago, but now i have filed a<a href="https://bugs.adobe.com/jira/browse/ASC-4077" target="_blank"> feature request</a> in the bug base of Adobe. I want const fields allow for being initialized in the constructor, too, not only inline. Here&#8217;s, what i wrote in the ticket:</p>
<blockquote><p>hello,</p>
<p>in the <a href="http://livedocs.adobe.com/specs/actionscript/3/as3_specification62.html),">AS3 specification</a> it says:<br />
&#8220;A variable declared with the const rather than the var keyword, is read-only outside of the variable&#8217;s intializer if it is not an instance variable and outside of the instance constructor if it is an instance variable. It is a verifier error to assign to a const variable outside of its writable region.&#8221;</p>
<p>This implies, that a const can be initialized in the constructor, but in fact, it cannot, when in strict mode.</p>
<p>In the past, there have been at least two bug reports around this, with slightly different outcome. An early report (<a title="intializing a const instance variable in the class constructor throws reference error" href="https://bugs.adobe.com/jira/browse/ASC-351"><span style="text-decoration: line-through;">ASC-351</span></a>) seemed to state, that it should be possible to initialize a const in the constructor. Unfortunately, from the report it is unclear, if strict mode was involved or not.</p>
<p>Another report later (<a title="Const initialized in constructor causing compiler error" href="https://bugs.adobe.com/jira/browse/ASC-3562"><span style="text-decoration: line-through;">ASC-3562</span></a>) stated, that it would only be possible without strict mode.</p>
<p>I do think, that const initialization should be possible in the constructor, like the AS3 specification suggests, even in strict mode. It would make the whole const concept more useful. For example, declaring a const in a superclass and giving it a value inline currently means, that in subclasses you cannot give it a different value, because you cannot re-declare the field and you cannot give it a different value in the constructor.</p>
<p>Also, you might want to do some checks to decide which value to assign to the const, which you could do in the constructor based on parameters or other factors.</p>
<p>From my point of view, adding the ability to initialize a const in the constructor in addition to do it inline as currently possible, will not break any existing code, since it just adds new functionality, but does not change or take away existing functionality (besides not throwing a compile time error anymore).</p></blockquote>
<p>So, what do you think? Do you agree? If yes, please <a href="https://bugs.adobe.com/jira/browse/ASC-4077" target="_blank">vote for the feature request</a> in the bug base. Otherwise, i still would be interested to read your opinion, of course <img src='http://www.ghost23.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/05/as3-feature-request-filed-const-initialization-in-constructor/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>abc file format specification &#8211; as a diagram</title>
		<link>http://www.ghost23.de/2010/04/abc-file-format-specification-as-a-diagram/</link>
		<comments>http://www.ghost23.de/2010/04/abc-file-format-specification-as-a-diagram/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 16:17:27 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[abc]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[diagram]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=278</guid>
		<description><![CDATA[Juten Tach, after all this thinking about not saving code as text anymore but in an object structure, i thought it might be worthwhile to understand a bit more about how ActionScript is built and what the elements are. What else to do but to dive into the specifications of ActionScript and the AVM2. Specifically i was [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>after all this thinking about not <a href="http://www.ghost23.de/2010/03/abstract-source-code-representation/">saving code as text anymore</a> but in an object structure, i thought it might be worthwhile to understand a bit more about how ActionScript is built and what the elements are. What else to do but to dive into the specifications of ActionScript and the AVM2. Specifically i was interested in the abc file format, nicely described in the PDF from Adobe: &#8220;<a href="http://www.adobe.com/devnet/actionscript/articles/avm2overview.pdf" target="_blank">ActionScript Virtual Machine 2 (AVM2) Overview</a>&#8220;.</p>
<p>Only problem was, it&#8217;s a lot of text and i usually can understand things better, if i see them visually. So i thought, it might be a good idea to make a diagram out of the textual description. So here it goes. I used Enterprise Architect to draw this, a very nice UML editor, by the way.</p>
<p><a href="http://www.ghost23.de/wp-content/uploads/ABCStructure.pdf"><img class="alignnone size-medium wp-image-279" title="abc file format specification diagram" src="http://www.ghost23.de/wp-content/uploads/abc-file-format_diagram-300x219.gif" alt="The abc file format specification diagram" width="300" height="219" /></a></p>
<p><strong>[Update]:</strong> I changed the format to PDF for better reading and printing.</p>
<p>I admit, there are still quite a lot of lines cutting across each other and making the whole thing still a bit hard to overlook, but hey, it&#8217;s a first version.</p>
<p>Perhaps this might come in handy for you, too, so i am posting this. Should you find mistakes in the diagram, a comment would be appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/04/abc-file-format-specification-as-a-diagram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Abstract source code representation</title>
		<link>http://www.ghost23.de/2010/03/abstract-source-code-representation/</link>
		<comments>http://www.ghost23.de/2010/03/abstract-source-code-representation/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 09:57:15 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[Codeparser]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=271</guid>
		<description><![CDATA[Juten Tach, shame on me for thinking &#8211; even just for a second &#8211; i could have been the first one with this idea. Of course not . As commenter Ben pointed out, there are thoughts about this subject already and they exist for some time now. There is Intentional Programming. IP has a lot [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>shame on me for thinking &#8211; even just for a second &#8211; i could have been the first one with <a href="http://www.ghost23.de/2010/03/source-code-stored-in-object-structures/">this idea</a>. Of course not <img src='http://www.ghost23.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . As commenter Ben pointed out, there are thoughts about this subject already and they exist for some time now.</p>
<p>There is <a href="http://en.wikipedia.org/wiki/Intentional_programming" target="_blank">Intentional Programming</a>. IP has a lot more in it than just the fact, that is proposes to have an abstract representation of code be stored instead of concrete code in text files. But the abstract representation seems to serve as a kind of basis for the whole thing. Intentional Programming is brought forward by <a href="http://www.intentsoft.com/" target="_blank">Intentional</a>, who are working on a software development system around the ideas of IP. They did a <a href="http://msdn.microsoft.com/en-us/data/dd727740.aspx" target="_blank">presentation</a> on the DSL DevCon 2009, which is a bit lengthy, but nevertheless awesome. Martin Fowler also wrote down some <a href="http://martinfowler.com/bliki/IntentionalSoftware.html" target="_blank">thoughts</a> on Intentional and their solution.</p>
<p>Then there is <a href="http://en.wikipedia.org/wiki/Semantic-oriented_programming" target="_blank">SOP</a> and a <a href="http://symade.tigris.org/" target="_blank">tool in early alpha stage</a>. Can&#8217;t say too much about it, as the guy is a Russian and Google Translate does not a very good job at translating from russion to german <img src='http://www.ghost23.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And lastly, there is another <a href="http://martinfowler.com/articles/languageWorkbench.html" target="_blank">good article</a> from Martin Fowler on the subject in general, which goes way beyond, what i am currently thinking about. Means, i am still at the stage of technical ideas and he is already taking the whole thing into the business world as well as Intentional does.</p>
<p>All this is truly inspiring. Would love to see something like this for Flash, i think it also could be the answer for true designer / developer collaboration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/03/abstract-source-code-representation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Source code stored in object structures</title>
		<link>http://www.ghost23.de/2010/03/source-code-stored-in-object-structures/</link>
		<comments>http://www.ghost23.de/2010/03/source-code-stored-in-object-structures/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 21:41:58 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[Codeparser]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=266</guid>
		<description><![CDATA[Juten Tach, there is a topic i&#8217;ve been thinking about lately, which is source code and the way we store it currently. Specifically, i do wonder, if storing source code as text is still the right way. Especially for languages, which are not run in an interpreted way, but compiled or pre-compiled i wonder, why [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>there is a topic i&#8217;ve been thinking about lately, which is source code and the way we store it currently. Specifically, i do wonder, if storing source code as text is still the right way. Especially for languages, which are not run in an interpreted way, but compiled or pre-compiled i wonder, why we actually store that code in text files.</p>
<p>If you look at all the tools we use, the IDEs, the compilers, UML modelling applications. All these tools currently take textual code and transform it into intermediate object structures, with which they work. Take code highlighting. For being able to have proper code highlighting, tools have to parse the text, understand the very basics of the structure of the code in order to do the highlighting.</p>
<p>Take code completion. The tool has to parse the textual source code into some kind of object structure in order to understand, what references, functions or objects to offer.</p>
<p>Take refactoring. The tool has to parse the textual source code into an object structure in order to change namings, move functions into different classes while updating the references and organizing imports and so on.</p>
<p>Take UML reverse engineering. The tool has to parse the textual source code into an object structure in order to build the represented class hierarchy that serves as the basis for visualizing that hierarchy in UML. All these tools work with object structures or syntax trees rather than with the text itself. Alle these tools have to parse the text over and over again.</p>
<p>In the end, that&#8217;s also, what the compiler does before it transforms the whole thing into binary instructions. So, i ask myself, wouldn&#8217;t it be more efficient to actually store the source code in some kind of object structure, so that these tools can make direct use of it instead of having to parse it again and again?</p>
<p>Googling this subject (i was not even sure, what to search for, because i couldn&#8217;t decide on good search terms), i only found <a href="http://c2.com/cgi/wiki?ProgramsAreDatabases" target="_blank">one wiki article</a>, that discussed that topic a little bit, but differently, as that the people there thought about storing source code in databases, which i am not so sure, whether this is the best way. But the thoughts behind that go into the same direction.</p>
<p>I understand, that storing source code in text files has some significant advantages, the most obvious being, that everyone can read text files, because it is so standard and minimal. Also, source code repositories make use of text and can handle it very intelligently.</p>
<p>But i think, since software applications today become more and more complex, wouldn&#8217;t development environments, that handle source code as object structures from the very start, be capable of handling that source code more efficiently and even more intelligently? If we would start thinking about source code as being a model and a textual representation of that model simply being one view (UML being another), wouldn&#8217;t that provide completely new possibilities for IDEs and the whole ecosystem of software development? In respect to MVC, doesn&#8217;t source code stored in text files currently strongly couple the model with the view, something we normally try to avoid as hard as we can? Things like indentation, the use of braces or brackets, specials keywords, semicolons and blank lines, aren&#8217;t these just visual decorations, either in order for us to be able to read the code or for the parser to parse it? Imagine, how code could look like, if we wouldn&#8217;t need those things, because we wouldn&#8217;t need a text parser.</p>
<p>Have you found articles on that topic? Would be curious to see them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/03/source-code-stored-in-object-structures/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The error problem in AS3</title>
		<link>http://www.ghost23.de/2009/11/the-error-problem-in-as3/</link>
		<comments>http://www.ghost23.de/2009/11/the-error-problem-in-as3/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 19:46:59 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[error]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/blog/?p=235</guid>
		<description><![CDATA[Juten Tach, this post was inspired by a topic, i am interested a bit lately, &#8220;Functional Programming&#8221;. There is a very informative series of videos over on channel9, that covers functional programming, moderated by Erik Meijer from Microsoft Research. I have not yet made it through every bit of the topic, but one thing, that has already [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>this post was inspired by a topic, i am interested a bit lately, &#8220;Functional Programming&#8221;. There is a very informative<a href="http://channel9.msdn.com/tags/C9+Lectures/" target="_blank"> series of videos</a> over on channel9, that covers functional programming, moderated by Erik Meijer from Microsoft Research. I have not yet made it through every bit of the topic, but one thing, that has already made a big impression on me is the statement, that functional programming emphasizes honesty of code. So what does that mean?</p>
<p>Honesty means, that a developer wanting to use a method for example, exactly knows, what to expect from it. In some sense, ActionScript has some limited honesty. Let&#8217;s take this method for example:</p>
<pre>var names:Vector.&lt;String&gt;;

function getName(id:int):String {
   return names[id];
}</pre>
<p>It seems to be honest about, what it returns, a String (we will see, it isn&#8217;t really honest about that). But it isn&#8217;t honest about what String. We could call this method three times with the same value for &#8216;id&#8217;, but we could not be sure, that we allways get the same result back, because the return value depends on the stuff, that is in the &#8216;names&#8217; Vector. This is called side effect. Functional programming tries to avoid side effects where possible. The aim is, whenever i give a specific value to a method, i should get back the same result. So the method is not only honest about the type of value, but also about the value itself.</p>
<p>OK, so far, so good. So what&#8217;s that to do with errors in ActionScript? Let&#8217;s look at the method again from above. If you try to use a Vector with an index out of the bounds of the Vector, you get a RangeError. By the way, i was astonished to recognize, that trying to do that with an Array simply returns null, while Vector throws an error. I find that to be a bit inconsistent. Anyway, what that means is, that our method getName()  could potentially throw an error instead of returning a String, as it declares. This might sound trivial, but i find it to be absolutely non-trivial. Strict typing means, that i as a programmer can expect, that if the method says, it returns a String, it will do so. But now we find, that it might not. getName() might not return anything, if an error occurs. Now you might reply &#8220;well, simply catch the error, and you&#8217;re good&#8221;. But how am i to know, that i have to? If i am responsible for the whole code base, i might know, that this method can throw an error, but what if the method is provided by some third-party library?</p>
<p>So this means, that ActionScript is not completely honest about return types, because we can only hope, that a method returns, what it says, but it might as well do nothing. Java tries to circumvent this problem with the &#8216;throws&#8217; clause. A method can define, that it either returns what it returns, or that it might throw an exception of a certain type. The point here is, the Java compiler will not compile a method, if it finds, that the code in that method might throw an exception, but that the method has not either catched it or declared via the &#8216;throws&#8217; clause, that the exception might occur (there are exceptions to this rule, but let&#8217;s just forget about these for a moment).</p>
<p>We don&#8217;t have that in ActionScript. In ActionScript, any method could potentially throw an error (not to speak of error events, which enlarges the problem even more) and we simply have no chance of knowing which method might throw which error. In the light of these thoughts it comes to no surprise, that the new flash player now supports global error handling, which for me feels like fixing a sympton rather than the cause. Catching errors globally is just another way of saying: &#8220;I have no idea, where all these errors come from, so let me simply catch them all in one place.&#8221;</p>
<p>To end up with, i want to repeat, that Array simply returns null, when trying to use it with an index out of the bounds of the Array. So it does not throw an error like Vector does. Looking at it from a functional-programming-point-of-view, this is more honest, than what the Vector does. If i would have made my example with an Array, getName() would allways return a String (well, not really, but null can be implicitly converted to a String by the runtime, so &#8230; it&#8217;s OK). That means, that the programm does not break and the contract is valid, the method is more honest. Of course, now you might have to deal with checking for null, as <a href="http://jessewarden.com/2007/11/your-mom-is-null-throws-exception-ot-ot-ot-or-learning-exception-handling-in-actionscript.html" target="_blank">Jesse Warden complaint about already</a>. A solution to this problem could be to return a default value instead of null. Of course, this will not work in all situations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2009/11/the-error-problem-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Singleton factory</title>
		<link>http://www.ghost23.de/2009/03/singleton-factory/</link>
		<comments>http://www.ghost23.de/2009/03/singleton-factory/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 14:42:29 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[factory]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[private class]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/blog/?p=99</guid>
		<description><![CDATA[Juten Tach, for my upcoming book i&#8217;m currently heads down in design patterns. Today i was actually looking for a good example for the proxy pattern, but instead had an idea for a Singleton factory. I know the discussion about Singleton being no good because of global state, bad testability and so on, but let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,<br/><br />
for my upcoming book i&#8217;m currently heads down in design patterns. Today i was actually looking for a good example for the proxy pattern, but instead had an idea for a Singleton factory. I know the discussion about Singleton being no good because of global state, bad testability and so on, but let&#8217;s just forget this for one moment and look at the implementation idea.<br/><br />
So, what i&#8217;m using here, is the not really documented feature of private classes. But today i found an example of a private class in the <a href="http://livedocs.adobe.com/flex/3/langref/Class.html" target="_blank">Adobe LiveDocs</a>, so this made me a little more hopeful, that this feature is not there coincidentally. So if you think, this is too hot, don&#8217;t read further. Otherwise, here it goes. First thing i do is, i create an interface, that describes my Singleton:<br/>
<pre>package {
   public interface ISingleton {
      function get someName():String;
      function set someName(value:String):void;
      function doSomething():void;
   }
}</pre>
<p>So, for this example, it is quite small and understandable, i guess. Next thing, i implement the Singleton and i implement a SingletonFactory, both in the same file, that&#8217;s why i was talking about private classes:<br/>
<pre>package {
   public final class SingletonFactory {
      private static var _singletonInstance:ISingleton;
      public static function getInstance():ISingleton {
         if (_singletonInstance == null) {
            _singletonInstance = new PrivateSingleton();
         }
         return _singletonInstance;
      }
   }
}

class PrivateSingleton implements ISingleton {
   private var _someName:String;
   public function get someName():String {
      return _someName;
   }

   public function set someName(value:String):void {
      _someName = value;
   }

   public function doSomething():void {
      trace("Doing something with: " + _someName);
   }
}</pre>
<p>So, as you can see, the PrivateSingleton is a private class, declared outside of the package definition, so it is only visible to SingletonFactory, no one else. PrivateSingleton, of course, implements ISingleton. And the SingletonFactory does, what Singletons normally do for themselves, it manages and creates the Singleton. I like that approach, because the responsibilities are separated nicely, the PrivateSingleton doesn&#8217;t actually know, that it is a Singleton. Should you ever decide to let it be a normal class, then you simply could put it into its own class file and things would still work, even for the SingletonFactory (although you probably would want to discard it then).<br/><br />
So, to use a Singleton like that, you would do something like this:<br/><br/>
<pre>var mySingleton:ISingleton = SingletonFactory.getInstance();
mySingleton.someName = "Hans";
mySingleton.doSomething();
</pre>
<p>Well, that&#8217;s it, nothing big, just one more solution for building a singleton. One additional advantage here is, that you get nice compile time errors, when trying to use PrivateSingleton inappropriately. Most AutoCompletions will not even propose the class. Drawback is, you cannot inherit from PrivateSingleton and you still might have that dim feeling, that using private classes might be wrong.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2009/03/singleton-factory/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The V in MVC</title>
		<link>http://www.ghost23.de/2009/02/the-v-in-mvc/</link>
		<comments>http://www.ghost23.de/2009/02/the-v-in-mvc/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 13:50:00 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[object oriented design]]></category>
		<category><![CDATA[rich user interface]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/blog/?p=98</guid>
		<description><![CDATA[Juten Tach, lately i was discussing a design with colleagues of mine for a specific project, they are working on. We talked about various principles and methodologies, actually the discussion wandered a bit from the actual topic. We talked about MVC and Domain Driven Design and in the end were confused, because we were uncertain [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,<br />
lately i was discussing a design with colleagues of mine for a specific project, they are working on. We talked about various principles and methodologies, actually the discussion wandered a bit from the actual topic. We talked about MVC and Domain Driven Design and in the end were confused, because we were uncertain as to what would be the best approach to design the application.</p>
<p>The application in question is one, that has a very rich user interface with animations, video, sophisticated controls and so on. The domain model that lies behind all that is rather simple though. It is one of those applications in the advertising industry, that is more about the show than about utility.</p>
<p>I would roughly estimate, that 60% of the code that my colleagues will write is related to the UI and the rest goes for the model and the general application logic. Actually most of the applications we develop are partitioned that way. That&#8217;s nothing to get excited about, after all we&#8217;re building thin clients and of course a thin client is mostly made up of ui code.</p>
<p>But knowing that, i come to ask myself, why we are actually so excited about MVC, Domain Driven Design, architectrual frameworks, IoC and stuff. For the particular type of flash applications that we build, we should be more concerned about how to structure the V in MVC than about the whole MVC in general. That&#8217;s not to say, we should not care about general architectural matters, but being a flash developer, who is building rich user interfaces, we should rather think about structuring our views than about structuring our model, since in many cases, our model is not the core of our problem, but the view is.</p>
<p><img alt="ecozoo.jpg" src="/blog/wp-content/uploads/ecozoo.jpg" width="480" height="232" /><small>Screenshot of the <a href="http://ecodazoo.com/" target="_blank">eco zoo</a> campaign.</small></p>
<p>However, i do see too little articles covering this topic in particular. I also do not see enough design frameworks trying to deliver support in that area. Of course, we have frameworks, that aim at simplifying building UIs, such as the Flex framework. But for me, these frameworks rather try to look at the UI to be something, that should be made easy, so you don&#8217;t have to think about it to deeply, so that you can concentrate on the application itself. But what, if the presentation is the thing, you want to concentrate on? That&#8217;s why i&#8217;m so sceptical about tools like Adobe Catalyst, because i have the feeling, this tool tries to hide away the problem of developing complex UIs, suggesting that the act of architecting and developing a rich UI is something, that can be somehow automated and hidden behind a clickable tool. I strongly believe, this is not possible. It takes experienced UI developers to build stunning presentation layers and these experienced developers should start thinking about effective ways of building those UIs.</p>
<p><img alt="ikea.jpg" src="http://www.ghost23.de/blog/images/ikea.jpg" width="480" height="317" /><small>Screenshot of the ikea <a href="http://demo.fb.se/e/ikea/comeintothecloset2/site/default.html">wardrobe solutions campaign</a>.</small></p>
<p>I think it is time, that we think more about the underlying patterns in the development of rich and animated UIs. A discussion about those should not only be about components, because really rich UIs are not solely made out of classic components. Of course, in a sense you can define everything to be some sort of button, but i feel that doesn&#8217;t live up with what we really need. Especially as we are heading to UIs, that are try to go away from classic form style in favor of more integrated, chromeless UIs. Also we need to incorporate timing in a more fluent way. We already have some very good state patterns yet, but my feeling is, that todays UIs go beyond simple state, our concern is not so much the state, but the transitions. And sometimes UIs are constantly transitioning, so that one might start to doubt, if it is even useful to talk about states anymore.</p>
<p>To make a long story short, i think with the advent of rich, interactive and animated UIs we need a deeper discussion about how we can build those in an effective way, that allows for the basic principles like extendability, maintainability and reusability.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2009/02/the-v-in-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pragmatic Design</title>
		<link>http://www.ghost23.de/2008/11/pragmatic-design/</link>
		<comments>http://www.ghost23.de/2008/11/pragmatic-design/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 12:00:00 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[cairngorm]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[puremvc]]></category>
		<category><![CDATA[structure]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/blog/?p=95</guid>
		<description><![CDATA[I have discussed a topic a lot lately with friends and colleagues: "Using <em>architectural</em> frameworks". I know some people, who use Cairngorm, pureMVC and the like in a lot of their projects and i know people (including me), who cultivate a solid scepticism about those frameworks.
]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,<br />
i have discussed a topic a lot lately with friends and colleagues: &#8220;Using <em>architectural</em> frameworks&#8221;. I know some people, who use Cairngorm, pureMVC and the like in a lot of their projects and i know people (including me), who practice a solid scepticism about those frameworks. Let me explain.<br />
For me, the very essence of object-oriented-software-development ist the fact, that it allows me to build my application according to objects and relationships from the real world. That means, i do not build my application based on algorithms or functions, but on concepts, that i directly take from the domain of the problem i am trying to solve.<br />
Something, that is not intended in purely functional or procedural languages. So for example, if the domain, in which i am about to build a program, deals with &#8220;shopping carts&#8221;, &#8220;customers&#8221;, &#8220;products&#8221; and so on, i can model these entities in the requirements specification, in the detailed concept, in the system design and best of all, directly in my code, using classes, interfaces, instances of classes and so on. For me, this is the true power of object-oriented-design. Objects, that have been described in some detailed concept make their way directly in my code and thus make it very readable and understandable and also provide, that the implementation is not necessarily bound to the intended functionality only, which means, it is easier to extend the software later on.<br />
And of course, it is not only about modeling those objects, it is also about modeling the relationships between those objects. What object should have connections to what other objects and what kind of connection would that be? How should the interface of a class look like, means how do i plan to ensure encapsulation, how do i make my classes cohesive and so on.  I think, designing an applications basic structure upfront &#8211; not in its entirety and into every detail of course, but the big picture &#8211; is vital and serves as a solid ground for even the most agile process. It helps developers not loosing focus on where the project should be heading to. Having the possibility to design such a solid basis gives me a good feeling for my projects. Of course, designing an appllication from scratch is a hard and time-consuming job and often goes wrong. But as allways, the more you do it, the better you get.<br />
Now, architectural frameworks aren&#8217;t bad. In fact, if in the design process, you come to the conclusion, that you want to build up your application on the MVC pattern, then it would be rather ineffective not to use something, that works out of the box, unless you have some good arguments against it. My argument here is, for letting object-orientation have its full effect, you should not start the design of your application with a sentence like &#8220;I will build this based on frameworkX&#8221;. But instead you should model the conceptual entities of your application and their relationships and let this model be your basis upon which you build your application. And if then you find, that &#8216;frameworkX&#8217; would fit into this with acceptable efforts, then everything&#8217;s fine.<br />
But i have the feeling &#8211; and please feel free to shout, if i am totally wrong here &#8211; that a lot of developers choose frameworks like Cairngorm or pureMVC not because the patterns fit good into their design, but because it slowly becomes common sense to use those frameworks. I hear sentences like: &#8220;Using Cairngorm means, developers instantly know the common structure of the project and thus can work together more effectively&#8221;. Or: &#8220;It is so handy. I put my controllers there, my model there. It&#8217;s easy.&#8221; Or the best one: &#8220;If you want to build software in todays RIA industry, you will not get around Cairngorm.&#8221;<br />
What can i say? It&#8217;s true, it&#8217;s easy. It is a very pragmatic approach and a lot of projects seem to proof, that it just works. But still, i think it&#8217;s not right. Of course, using Cairngorm doesn&#8217;t mean, that you can&#8217;t build a good application structure. Of course you can still build up your domain model along the real-world entities. But you allways have to play their game, if you want the concept to be effective. You have to stick to MVC, even if in some cases you might think, it doesn&#8217;t make sense. OK, you don&#8217;t have to, but i feel, not sticking to the concept of Cairngorm or pureMVC, but still using it makes things even worse, because it means breaking conventions, that other developers count on.<br />
The biggest concern though for me is, those frameworks might give some developers a delusive feeling of comfort about their application being well structured, only because they used such a framework. So, if you design your application and you come to the conclusion, that you want to build it up using a paradigm like MVC, then cool, go ahead. But if you find yourself using an architectural framework because you did so for last 10 projects, you should at least ask yourself, if there could be an alternative.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2008/11/pragmatic-design/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Extreme Programming &#8211; alternative viewpoint</title>
		<link>http://www.ghost23.de/2008/10/extreme-programming-alternative-viewpoint/</link>
		<comments>http://www.ghost23.de/2008/10/extreme-programming-alternative-viewpoint/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 10:00:00 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[Stuff]]></category>
		<category><![CDATA[agile development]]></category>
		<category><![CDATA[criticism]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[extreme programming]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/blog/?p=94</guid>
		<description><![CDATA[Juten Tach, XP is very popular these days. Critical voices are rare. So this document from Gerold Keefer from AVOCA GmbH tries to balance the viewpoints a bit: http://www.avocallc.de/downloads/ExtremeProgramming.pdf]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,<br />
XP is very popular these days. Critical voices are rare. So this document from Gerold Keefer from AVOCA GmbH tries to balance the viewpoints a bit: <a href="http://www.avocallc.de/downloads/ExtremeProgramming.pdf" target="_blank">http://www.avocallc.de/downloads/ExtremeProgramming.pdf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2008/10/extreme-programming-alternative-viewpoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
