<?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>Tue, 03 Jan 2012 15:21:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>AS3 &#8211; internal class, public method</title>
		<link>http://www.ghost23.de/2011/01/as3-internal-class-public-method/</link>
		<comments>http://www.ghost23.de/2011/01/as3-internal-class-public-method/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 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[class]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=441</guid>
		<description><![CDATA[Juten Tach, a little quiz again. We have three classes: The first one is the main class of our swf, InternalTest: package &#123; &#160; import flash.display.Sprite; import testPackage.PublicClass; &#160; public class InternalTest extends Sprite &#123; public function InternalTest&#40;&#41; &#123; &#160; var publicClass:PublicClass = new PublicClass&#40;&#41;; var ref:Object = publicClass.returnInternalClassRef&#40;&#41;; ref.doSomething&#40;&#41;; ref.doSomethingInternally&#40;&#41;; &#125; &#125; &#125; Ok, in [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>a little quiz again. We have three classes:</p>
<p>The first one is the main class of our swf, InternalTest:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">import</span> testPackage<span style="color: #000066; font-weight: bold;">.</span>PublicClass<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> InternalTest <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> InternalTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #6699cc; font-weight: bold;">var</span> publicClass<span style="color: #000066; font-weight: bold;">:</span>PublicClass = <span style="color: #0033ff; font-weight: bold;">new</span> PublicClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         <span style="color: #6699cc; font-weight: bold;">var</span> ref<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = publicClass<span style="color: #000066; font-weight: bold;">.</span>returnInternalClassRef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         ref<span style="color: #000066; font-weight: bold;">.</span>doSomething<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         ref<span style="color: #000066; font-weight: bold;">.</span>doSomethingInternally<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Ok, in a package &#8220;testPackage&#8221; we have two other classes, PublicClass and InternalClass.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> testPackage <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PublicClass <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> returnInternalClassRef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>InternalClass <span style="color: #000000;">&#123;</span>
         <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> InternalClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> testPackage <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> InternalClass <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doSomething<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;InternalClass did something!!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #339966; font-weight: bold;">function</span> doSomethingInternally<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;InternalClass did something internally!!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now make a guess, what happens?</p>
<p>Well, it&#8217;s not too hard to figure out, right? But interesting to remember anyway. The call for doSomething() works, whereas the call for doSomethingInternally() ends up in an exception. So if you define an internal class, you can still pass its reference outside its package (loosing the type obviously). Any public methods can be called then, but internal methods not. Makes sense, does it? I was just thinking about it, because i asked myself, why one would declare a class internal, but still have public methods.</p>
<p>So it only makes sense, if you want to pass it around as either an untyped reference or as a casted interface implementation. Means, you could have an interface outside the package and the internal class implements it. Then within the package you could use the class by its direct class type and outside you would use it by its interface type.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2011/01/as3-internal-class-public-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Events vs. Callbacks &#8211; when to use what</title>
		<link>http://www.ghost23.de/2010/10/events-vs-callbacks-when-to-use-which/</link>
		<comments>http://www.ghost23.de/2010/10/events-vs-callbacks-when-to-use-which/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 14:06:39 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[callbacks]]></category>
		<category><![CDATA[events]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=380</guid>
		<description><![CDATA[Juten Tach, A commenter in a previous post said, he loves callbacks. That made me think about the difference and about why we mostly use events and not callbacks. I think one reason is, because the Flash Player is using events all over the place. But is using events always the best solution? I am [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>A commenter in a previous post said, he loves callbacks. That made me think about the difference and about why we mostly use events and not callbacks. I think one reason is, because the Flash Player is using events all over the place. But is using events always the best solution? I am not talking about performance here, i am more interested in the underlying concepts. Here&#8217;s a classification, i would like to propose( I have been searching the web for existing classifications. If you find one, please shout):</p>
<blockquote><p>You should use a callback, when you&#8217;re client initiates an asynchronous call and awaits an answer to it.</p></blockquote>
<h3>Rationale</h3>
<p>In Flash &#8211; as opposed to Java &#8211;  we are forced to do a lot of things asynchronously. The most popular example is loading a file. We as a client want to load a file and we want to be notified, when that process &#8211; the process, that we have initiated &#8211; is complete. We don&#8217;t want to be notified of loading events in general, no, we just want to know, when our initiated process has finished. A good way to detect a potential use case for such a scenario is, if you remove yourself as a listener in the event handler method. It is a good indicator, that you actually just wanted a callback.</p>
<p>The advantage of callbacks here is, that your intention becomes directly visible. If your calling a method, which takes a callback function, it is crystal clear, what is happening. You&#8217;re doing an asynchronous call and you are waiting for THAT call to finish. With events, you often have the problem, that the line in your code, where you added yourself as a listener, and the line in your code, where you are initiating the asynchronous call, might be in completely different places, which makes it hard to understand for another developer.</p>
<p>With callbacks, you have everything in one place and you can even check at runtime, that the callback is indeed a function and not null. You cannot check at runtime, if a client has added himself as a listener for a particular event before calling a specific method.</p>
<blockquote><p>You should use events, when something can happen unexpectedly</p></blockquote>
<h3>Rationale</h3>
<p>There are scenarios, in which you as a client have not initiated an asynchronous process by yourself, yet something still might happen. As an example, let&#8217;s consider an application with a shared model and different modules, that consume and feed it. ModuleX might want to be notified, when a particular value in the model changes. Yet, ModuleX might not do anything to force that. Instead another Module is doing something, that changes that particular value. Then the model dispatches an event, saying that the value has changed.</p>
<p>So in this case, the event comes unexpected for ModuleX. Unexpected, because ModuleX has not initiated an asynchronous process, which led to this event. ModuleX might have been idle for some time and now the event comes in and it lets ModuleX do, whatever it wants to do in that case. You cannot use a callback in this scenario, because the client didn&#8217;t want to start a process. Instead it really just wanted to be notified more generally, when something happens.</p>
<p>Another very popular example, where events make sense, is user interaction. You create a button and wait for a user to click on it. But the button does not force the user to click on it as part of a sequential process. Instead, the button just waits, until it might happen (which might be never). A callback would not make sense here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/10/events-vs-callbacks-when-to-use-which/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>One swf, multiple Classes, multiple ApplicationDomains</title>
		<link>http://www.ghost23.de/2010/10/one-swf-multiple-classes-multiple-applicationdomains/</link>
		<comments>http://www.ghost23.de/2010/10/one-swf-multiple-classes-multiple-applicationdomains/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 14:55:37 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[ApplicationDomain]]></category>
		<category><![CDATA[modularity]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=351</guid>
		<description><![CDATA[Juten Tach, say, you have a swf file, that contains some functionality, that you want to use in a main application. Roughly, this functionality will consist of an interface (by which in this case i mean a bunch of classes, which make the functionality public to the client classes) and the internal implementation (a bunch [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>say, you have a swf file, that contains some functionality, that you want to use in a main application. Roughly, this functionality will consist of an interface (by which in this case i mean a bunch of classes, which make the functionality public to the client classes) and the internal implementation (a bunch of classes behind the interface, which do the real work).</p>
<p>In a modular world, it would be nice to have the implementation be separate from the interface. In fact, so separate, that you could exchange it at runtime, if you wish to do so. So to be concrete, it would be nice, if the interface classes would be loaded into the main <span style="font-family:monospace; font-size:larger">ApplicationDomain</span>, so that everybody can use them and that the implementation classes would be loaded into a child <span style="font-family:monospace; font-size:larger">ApplicationDomain</span>, so that i could exchange them at runtime, if i want to.</p>
<p>No problem, you say, make two swf files. One with the interfaces, one with the implementation. Bahh, i answer, because i don&#8217;t want to spread my module over two swf files.</p>
<p>The solution is: Frames! The idea goes like this:</p>
<ol>
<li>You create your interface classes (again, these are not necessarily just interfaces, might also be some classes). You will also want to create some kind of factory or facade, which will create the real instances and decouple the implementation from your interface. Within the facade or factory, you have to use <span style="font-family:monospace; font-size:larger">getDefinitionByName(&#8230;)</span>  to reference the implementation, because you don&#8217;t want your implementation to get compiled into this frame. The facade will be the only place, where the implementation is indirectly referenced. The interface should have no references to the implementation (why would it anyway?!).</li>
<li>You create your implementation. The implementation can have references to the interface, of course. Probably mostly in the form of inheritance, or interface implementation and of course composition.</li>
<li>Now you build your swf, either using the <span style="font-family:monospace; font-size:larger">-frame</span> compiler option or the <span style="font-family:monospace; font-size:larger">Frame</span> Metatag. Make sure, that the facade/factory and the interface compiles into the first frame and the implementation compiles into the second frame. It would make sense, that the Facade/Factory is actually the main class for your swf, so it has to extend <span style="font-family:monospace; font-size:larger">MovieClip</span>. This main class has to make sure, that it stops at the first frame, once the swf is loaded. Very important!</li>
<li>Now, in your main application, you need to implement some loading logic, that actually does the magic.</li>
<li>You load the swf from above into the main <span style="font-family:monospace; font-size:larger">ApplicationDomain</span> by using <span style="font-family:monospace; font-size:larger">ApplicationDomain.currentDomain</span>. Since the swf stops at the first frame, only the classes from the first frame are now available to your application. These are: The factory/facade and the interface classes.</li>
<li>Now you load the same swf a second time, but not using <span style="font-family:monospace; font-size:larger">Loader.load(&#8230;)</span>, but instead using <span style="font-family:monospace; font-size:larger">Loader.loadBytes(&#8230;)</span> in conjunction with <span style="font-family:monospace; font-size:larger">Loader.contentLoaderInfo.bytes</span>. And this time, you load it into a child <span style="font-family:monospace; font-size:larger">ApplicationDomain</span>, using <span style="font-family:monospace; font-size:larger">new ApplicationDomain(ApplicationDomain.currentDomain)</span>. This way, the whole thing goes faster, and you don&#8217;t have to actually make a new request over the net.</li>
<li>And now, you tell this newly loaded swf to go to second frame, which makes the implementation classes available (Since it started in the first frame, the facade/factory and interface classes are also loaded again, but they will be ignored this time, because they already exist in the main <span style="font-family:monospace; font-size:larger">ApplicationDomain</span>). But now the implementation classes are only available in the child <span style="font-family:monospace; font-size:larger">ApplicationDomain</span>.</li>
<li>Make sure, that you never go to the second frame in the first loaded <span style="font-family:monospace; font-size:larger">Loader</span> (you might want to nullify it, so you don&#8217;t accidentally do it). Because then, the whole benefit would be lost, because the implementation then would also exist in the main <span style="font-family:monospace; font-size:larger">ApplicationDomain</span>.</li>
</ol>
<p>That&#8217;s it. This way, you can now unload the implementation and load a new one, if necessary. The facade/factory and the interfaces will stay. Which brings up a little catch: If you want to exchange the implementation successfully, you have to make sure, that class paths are always the same in the different implementations, otherwise, the facade wouldn&#8217;t work, of course. You could circumvent this, if you put the facade into the implementation frame as well and let some generic mechanics in the main application do the fetching.</p>
<p>Testing this, by the way, i found that jumping to a frame three (with <span style="font-family:monospace; font-size:larger">gotoAndStop(3)</span>) always introduces the classes in a frame two as well. Which is a pity, because otherwise you would have been very flexible in deciding, which classes you want to put in which <span style="font-family:monospace; font-size:larger">ApplicationDomain</span>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/10/one-swf-multiple-classes-multiple-applicationdomains/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A thought about interfaces in ActionScript</title>
		<link>http://www.ghost23.de/2010/09/a-thought-about-interfaces-in-actionscript/</link>
		<comments>http://www.ghost23.de/2010/09/a-thought-about-interfaces-in-actionscript/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 13:12:01 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=346</guid>
		<description><![CDATA[Juten Tach, i am currently porting some code from Java to ActionScript. And of course, doing that makes some differences between these languages directly visible. One thing for example is: getter/setter methods. I love the ActionScript getter/setter approach. I think, it is pretty well-thought-out. The good thing about it is, that they look like a [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>i am currently porting some code from Java to ActionScript. And of course, doing that makes some differences between these languages directly visible. One thing for example is: getter/setter methods. I love the ActionScript getter/setter approach. I think, it is pretty well-thought-out. The good thing about it is, that they look like a property. Which has the nice benefit, that in ActionScript you can always start with a public property first and change it to getter/setter, if you want to do something during assignment or return, or if you simply want to prohibit assignment. This is completely different to Java, where the rule of thumb is to always use getter and setter methods in the first place. Which makes absolute sense there, because getters have a different appearance to a client than properties.</p>
<p>Now, since getters and setters are so different in ActionScript compared to Java, i think, Interfaces in ActionScript should also look different, at least for some details. The job of an interface is to describe how to use an object. It should not describe, how the object implements functionality. Thus in Java only methods are allowed to be defined in an interface (and static properties for some reason). Which makes sense, because for accessing properties, in Java you would certainly use getter and setter methods.</p>
<p>ActionScript is different though. And that&#8217;s why i think, in ActionScript it should be allowed to define properties in an interface and let an implementing class decide, if it implements these properties using a real public property or getter and setters. Only if you want implementing classes to implement a read-only property, you would add the &#8220;get&#8221; keyword to the definition in the interface. So, an interface, that would want to define a property that is read-write enabled, could look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">interface Something <span style="color: #000000;">&#123;</span>
   <span style="color: #6699cc; font-weight: bold;">var</span> myPublicField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And a class implementing that interface could start with implementing that field with a simple class variable, OR by using setters and getters, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">class</span> Someone implements Something <span style="color: #000000;">&#123;</span>
   <span style="color: #6699cc; font-weight: bold;">var</span> _myPublicField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> myPublicField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">return</span> _myPublicField<span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> myPublicField<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>everythingIsOK<span style="color: #000000;">&#41;</span> _myPublicField = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">...</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And an interface wanting to restrict the field to read-only could add the &#8220;get&#8221; keyword:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">interface SomethingReadOnly <span style="color: #000000;">&#123;</span>
   <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #0033ff; font-weight: bold;">get</span> myPublicField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Note, that i am not so focused on the concrete notation here. Probably there could be better ways to notate these things. The point is, currently the only thing you can do in an interface is to define getter and setter functions, which automatically means, you have to implement them, even if a public property would be sufficient for a start. So the interface in fact defines the way to implement the field, which it shouldn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/09/a-thought-about-interfaces-in-actionscript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<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; &#34;one&#34; &#124;&#124; &#34;two&#34;; 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>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> result<span style="color: #000066; font-weight: bold;">:*</span> = <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #990000;">&quot;one&quot;</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #990000;">&quot;two&quot;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> responsibility <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Request <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> stuffToBeProcessed<span style="color: #000066; font-weight: bold;">:*;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> responsibility <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> interface Responsible <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #3f5fbf;">/**
       * Checks, if this class can handle the request.
       * @return An instance of Responsible or null.
       */</span>
      <span style="color: #339966; font-weight: bold;">function</span> checkResponsibility<span style="color: #000000;">&#40;</span>request<span style="color: #000066; font-weight: bold;">:</span>Request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>Responsible<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #3f5fbf;">/**
       * Processes the request.
       */</span>
      <span style="color: #339966; font-weight: bold;">function</span> doIt<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> responsibility <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ResponsibleOfStrings implements Responsible <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> checkResponsibility<span style="color: #000000;">&#40;</span>request<span style="color: #000066; font-weight: bold;">:</span>Request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>Responsible <span style="color: #000000;">&#123;</span>
         <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>request<span style="color: #000066; font-weight: bold;">.</span>stuffToBeProcessed <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">;</span>
         <span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doIt<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ResponsibleOfStrings is doing it!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #9900cc; font-weight: bold;">package</span> responsibility <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ResponsibleOfNumbers implements Responsible <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> checkResponsibility<span style="color: #000000;">&#40;</span>request<span style="color: #000066; font-weight: bold;">:</span>Request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>Responsible <span style="color: #000000;">&#123;</span>
         <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>request<span style="color: #000066; font-weight: bold;">.</span>stuffToBeProcessed <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">;</span>
         <span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doIt<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ResponsibleOfNumbers is doing it!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> responsibility <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ChainOfResponsibility <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> listOfResponsibleObjects<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addResponsibleObject<span style="color: #000000;">&#40;</span>responsibleObject<span style="color: #000066; font-weight: bold;">:</span>Responsible<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         listOfResponsibleObjects<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>responsibleObject<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> determineResponsibleObject<span style="color: #000000;">&#40;</span>request<span style="color: #000066; font-weight: bold;">:</span>Request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>Responsible <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #6699cc; font-weight: bold;">var</span> result<span style="color: #000066; font-weight: bold;">:</span>Responsible = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> listOfResponsibleObjects<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            result <span style="color: #000066; font-weight: bold;">||</span>= listOfResponsibleObjects<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>checkResponsibility<span style="color: #000000;">&#40;</span>request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         <span style="color: #000000;">&#125;</span>
&nbsp;
         <span style="color: #0033ff; font-weight: bold;">return</span> result<span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">import</span> responsibility<span style="color: #000066; font-weight: bold;">.*;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #6699cc; font-weight: bold;">var</span> chainOfResponsibility<span style="color: #000066; font-weight: bold;">:</span>ChainOfResponsibility = <span style="color: #0033ff; font-weight: bold;">new</span> ChainOfResponsibility<span style="color: #000066; font-weight: bold;">;</span>
         chainOfResponsibility<span style="color: #000066; font-weight: bold;">.</span>addResponsibleObject<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> ResponsibleOfNumbers<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         chainOfResponsibility<span style="color: #000066; font-weight: bold;">.</span>addResponsibleObject<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> ResponsibleOfStrings<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000066; font-weight: bold;">:</span>Request = <span style="color: #0033ff; font-weight: bold;">new</span> Request<span style="color: #000066; font-weight: bold;">;</span>
         request<span style="color: #000066; font-weight: bold;">.</span>stuffToBeProcessed = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #6699cc; font-weight: bold;">var</span> responsibleObject<span style="color: #000066; font-weight: bold;">:</span>Responsible = chainOfResponsibility<span style="color: #000066; font-weight: bold;">.</span>determineResponsibleObject<span style="color: #000000;">&#40;</span>request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         responsibleObject<span style="color: #000066; font-weight: bold;">.</span>doIt<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">names</span><span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>String<span style="color: #000066; font-weight: bold;">&gt;;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> getName<span style="color: #000000;">&#40;</span>id<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">names</span><span style="color: #000000;">&#91;</span>id<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<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>
	</channel>
</rss>

