<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Runtime Enforcement of Abstract Classes in AS3</title>
	<atom:link href="http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 31 Jan 2012 13:51:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-23476</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Sun, 11 Dec 2011 01:40:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-23476</guid>
		<description>Seems like a reasonable approach, Solstice_Of_Light. Usually, what I do these days is create an interface, implement all of its methods in a base class, but leave out the &lt;code&gt;implements IWhatever&lt;/code&gt;. Then, then subclass needs to do it. Enforcing anything else beyond that amounts to busywork, in my opinion.</description>
		<content:encoded><![CDATA[<p>Seems like a reasonable approach, Solstice_Of_Light. Usually, what I do these days is create an interface, implement all of its methods in a base class, but leave out the <code>implements IWhatever</code>. Then, then subclass needs to do it. Enforcing anything else beyond that amounts to busywork, in my opinion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Solstice_Of_Light</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-23470</link>
		<dc:creator>Solstice_Of_Light</dc:creator>
		<pubDate>Sun, 11 Dec 2011 01:02:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-23470</guid>
		<description>Couldn&#039;t you emulate an abstract class with errors at compile time by splitting the problem in two? Your base class is a normal class which contains all the pre-defined methods. A second (supplementary) class is an interface with all the to-be-implemented methods. The base class REQUIRES that an (implemented) version of the interface is passed in the constructor. 

---
Class pseudo-abstract{

private var implementedmethods:IUnimplementedmethods;

public function constructor(implementedClass:IUnimplementedmethods){

this.implementedmethods = implementedClass;

}

public function implementedfunction(){

...code...

}

public function unimplementedmethod(){

implementedmethods.unimplementedmethods();

}

}
---

I&#039;m not an actionscript user, so please excuse my syntax ...
Note that you could even emulate overriding by &quot;try{implementedmethods.implementedfunction()}
catch(error){...code...}&quot;
if there&#039;s anything similar available in AS.</description>
		<content:encoded><![CDATA[<p>Couldn&#8217;t you emulate an abstract class with errors at compile time by splitting the problem in two? Your base class is a normal class which contains all the pre-defined methods. A second (supplementary) class is an interface with all the to-be-implemented methods. The base class REQUIRES that an (implemented) version of the interface is passed in the constructor. </p>
<p>&#8212;<br />
Class pseudo-abstract{</p>
<p>private var implementedmethods:IUnimplementedmethods;</p>
<p>public function constructor(implementedClass:IUnimplementedmethods){</p>
<p>this.implementedmethods = implementedClass;</p>
<p>}</p>
<p>public function implementedfunction(){</p>
<p>&#8230;code&#8230;</p>
<p>}</p>
<p>public function unimplementedmethod(){</p>
<p>implementedmethods.unimplementedmethods();</p>
<p>}</p>
<p>}<br />
&#8212;</p>
<p>I&#8217;m not an actionscript user, so please excuse my syntax &#8230;<br />
Note that you could even emulate overriding by &#8220;try{implementedmethods.implementedfunction()}<br />
catch(error){&#8230;code&#8230;}&#8221;<br />
if there&#8217;s anything similar available in AS.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Painter</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-17637</link>
		<dc:creator>Peter Painter</dc:creator>
		<pubDate>Fri, 23 Sep 2011 13:20:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-17637</guid>
		<description>One thing about abstract classes that has been completely ignored so far is that an interface cannot declare Events, Styles etc.

So all the support in Flex Builder and MXML for easy creation of event handlers and style properties fails if your MXML class has a member that is defined by just an interface.

For detection of a direct instantiation, I don&#039;t use a self parameter. I rather compare the class name of the current this pointer with the static class name:

if( flash.utils.getQualifiedClassName(this).substring(2+flash.utils.getQualifiedClassName(this).indexOf(&quot;::&quot;))==&quot;myClassName&quot;) { throw Error...};

Some of my abstract classes contain a static function that instantiates the proper descendant based on additional parameters.

Things would be much easier if you could simply declare the constructor of the base class as protected. All that is to for implementing this is to remove the error check for a non-public constructor from the compiler and it should work as expected. I&#039;m sure the compiler would do the right thing (and throw the right errors) if you only could get past the &#039;constructors must be public&#039; check.

Even a private constructor could be useful, when designing a managed class.</description>
		<content:encoded><![CDATA[<p>One thing about abstract classes that has been completely ignored so far is that an interface cannot declare Events, Styles etc.</p>
<p>So all the support in Flex Builder and MXML for easy creation of event handlers and style properties fails if your MXML class has a member that is defined by just an interface.</p>
<p>For detection of a direct instantiation, I don&#8217;t use a self parameter. I rather compare the class name of the current this pointer with the static class name:</p>
<p>if( flash.utils.getQualifiedClassName(this).substring(2+flash.utils.getQualifiedClassName(this).indexOf(&#8220;::&#8221;))==&#8221;myClassName&#8221;) { throw Error&#8230;};</p>
<p>Some of my abstract classes contain a static function that instantiates the proper descendant based on additional parameters.</p>
<p>Things would be much easier if you could simply declare the constructor of the base class as protected. All that is to for implementing this is to remove the error check for a non-public constructor from the compiler and it should work as expected. I&#8217;m sure the compiler would do the right thing (and throw the right errors) if you only could get past the &#8216;constructors must be public&#8217; check.</p>
<p>Even a private constructor could be useful, when designing a managed class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Thorpe</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-15683</link>
		<dc:creator>Steve Thorpe</dc:creator>
		<pubDate>Wed, 17 Aug 2011 21:02:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-15683</guid>
		<description>And rather than maintain an array of abstract methods a unique prefix naming convention could be applied to abstract methods and used to search for them in the reflection. for example if a double underscore prefix (&quot;__&quot;) is used uniquely for abstract method names then during instantiation the following code, implemented in the constructor of MyAbstractClass, will throw an error on the first abstract method it finds which is not implemented in the subclass. 

&lt;pre&gt;var methods:XMLList = describeType(this).method;
for (var m in methods){
	if ((methods[m].@name.substr(0,2) == &quot;__&quot;) &amp;&amp; (methods[m].@declaredBy == &quot;MyAbstractClass&quot; )){
	throw Error(methods[m].@name + &quot; is an abstract method, not implemented in subclass:&quot; + Object(this).constructor);					
	}
}&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>And rather than maintain an array of abstract methods a unique prefix naming convention could be applied to abstract methods and used to search for them in the reflection. for example if a double underscore prefix (&#8220;__&#8221;) is used uniquely for abstract method names then during instantiation the following code, implemented in the constructor of MyAbstractClass, will throw an error on the first abstract method it finds which is not implemented in the subclass. </p>
<pre>var methods:XMLList = describeType(this).method;
for (var m in methods){
	if ((methods[m].@name.substr(0,2) == "__") &amp;&amp; (methods[m].@declaredBy == "MyAbstractClass" )){
	throw Error(methods[m].@name + " is an abstract method, not implemented in subclass:" + Object(this).constructor);
	}
}</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Thorpe</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-15676</link>
		<dc:creator>Steve Thorpe</dc:creator>
		<pubDate>Wed, 17 Aug 2011 18:22:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-15676</guid>
		<description>Similar to Shaun&#039;s solution (requires no special processing in subclasses) but works in Flash Pro as well as FB :

In constructor of MyAbstractClass add:

&lt;pre&gt;if (Object(this).constructor == MyAbstractClass)
     throw new Error(&quot;MyAbstractClass is an abstract class&quot;);&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Similar to Shaun&#8217;s solution (requires no special processing in subclasses) but works in Flash Pro as well as FB :</p>
<p>In constructor of MyAbstractClass add:</p>
<pre>if (Object(this).constructor == MyAbstractClass)
     throw new Error("MyAbstractClass is an abstract class");</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shaun</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-12719</link>
		<dc:creator>Shaun</dc:creator>
		<pubDate>Thu, 30 Jun 2011 19:54:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-12719</guid>
		<description>Sorry to amend my original post, the class CommonParserBase is my abstract class and this code would live in that classes constructor, essentially saying if an object calls this things constructor it has to be some object typed as something else (that is a subclass).</description>
		<content:encoded><![CDATA[<p>Sorry to amend my original post, the class CommonParserBase is my abstract class and this code would live in that classes constructor, essentially saying if an object calls this things constructor it has to be some object typed as something else (that is a subclass).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shaun</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-12718</link>
		<dc:creator>Shaun</dc:creator>
		<pubDate>Thu, 30 Jun 2011 19:52:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-12718</guid>
		<description>Know this is an oldie, but just figured I&#039;d tag another solution into here that seems to work fine at least in my current version of FB 3.4

In the constructor:
&lt;pre&gt;if(getClass(this)==CommonParserBase)
    throw new Error(&quot;This class is abstract only instantiate sub-classes.&quot;);&lt;/pre&gt;

It results in a string comparison and requires no changes to the constructor of the abstract or concrete sub classes.  I still have no good solution for finding un-implemented methods, the best I can think of is to break apart the interfaces and have the sub-classes implement a secondary interface which essentially contains what you would consider the unimplemented methods of the abstract class (in essence achieving the goal but with more files than should be necessary and possibility for confusion where abstract classes would make this clear).  Also @Zeljko I think there&#039;s a decent explanation of why you would do this above, if you ever use abstract classes in another language such as Java (among other things I miss from Java like overloading) you&#039;d be able to more easily understand why this is really nice to have.
http://download.oracle.com/javase/tutorial/java/IandI/abstract.html
http://www.javacoffeebreak.com/faq/faq0084.html
What it comes down to is the abstract class acts much like an interface requiring certain implementations to be handled by the implementing class, however unlike interfaces, abstract classes can contain some of the functionality.  As an alternative to my suggestion of breaking down the interface you could also just create a test case that calls all the methods and in the &quot;abstract&quot; version have it throw an error, create an instance of each concrete class in the test then call all methods of the &quot;abstract&quot; class that require concrete implementation.  This avoids the overhead of the run time solution and would help catch errors early, the only caveat is having to use a test framework like flex unit to execute the test class.</description>
		<content:encoded><![CDATA[<p>Know this is an oldie, but just figured I&#8217;d tag another solution into here that seems to work fine at least in my current version of FB 3.4</p>
<p>In the constructor:</p>
<pre>if(getClass(this)==CommonParserBase)
    throw new Error("This class is abstract only instantiate sub-classes.");</pre>
<p>It results in a string comparison and requires no changes to the constructor of the abstract or concrete sub classes.  I still have no good solution for finding un-implemented methods, the best I can think of is to break apart the interfaces and have the sub-classes implement a secondary interface which essentially contains what you would consider the unimplemented methods of the abstract class (in essence achieving the goal but with more files than should be necessary and possibility for confusion where abstract classes would make this clear).  Also @Zeljko I think there&#8217;s a decent explanation of why you would do this above, if you ever use abstract classes in another language such as Java (among other things I miss from Java like overloading) you&#8217;d be able to more easily understand why this is really nice to have.<br />
<a href="http://download.oracle.com/javase/tutorial/java/IandI/abstract.html" rel="nofollow">http://download.oracle.com/javase/tutorial/java/IandI/abstract.html</a><br />
<a href="http://www.javacoffeebreak.com/faq/faq0084.html" rel="nofollow">http://www.javacoffeebreak.com/faq/faq0084.html</a><br />
What it comes down to is the abstract class acts much like an interface requiring certain implementations to be handled by the implementing class, however unlike interfaces, abstract classes can contain some of the functionality.  As an alternative to my suggestion of breaking down the interface you could also just create a test case that calls all the methods and in the &#8220;abstract&#8221; version have it throw an error, create an instance of each concrete class in the test then call all methods of the &#8220;abstract&#8221; class that require concrete implementation.  This avoids the overhead of the run time solution and would help catch errors early, the only caveat is having to use a test framework like flex unit to execute the test class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zeljko</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-11236</link>
		<dc:creator>Zeljko</dc:creator>
		<pubDate>Fri, 10 Jun 2011 17:00:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-11236</guid>
		<description>Like every advanced tutorial, in this also some thing is missing. The answer to question &quot;Why to use it?&quot;</description>
		<content:encoded><![CDATA[<p>Like every advanced tutorial, in this also some thing is missing. The answer to question &#8220;Why to use it?&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Magic</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-10628</link>
		<dc:creator>Magic</dc:creator>
		<pubDate>Tue, 31 May 2011 22:14:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-10628</guid>
		<description>Hi,

There&#039;s a bit simpler way of faking an abstract class.

&lt;pre&gt;package
{
    public class AbstractClass
    {
        public function AbstractClass()
        {
            if(String(super) == &quot;[object AbstractClass]&quot;) throw new Error(&quot;This class is abstract and it cannot be instantiated&quot;);
        }
     }
}&lt;/pre&gt;

Cheers.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>There&#8217;s a bit simpler way of faking an abstract class.</p>
<pre>package
{
    public class AbstractClass
    {
        public function AbstractClass()
        {
            if(String(super) == "[object AbstractClass]") throw new Error("This class is abstract and it cannot be instantiated");
        }
     }
}</pre>
<p>Cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruno Caxito</title>
		<link>http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-4162</link>
		<dc:creator>Bruno Caxito</dc:creator>
		<pubDate>Wed, 16 Feb 2011 13:51:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/#comment-4162</guid>
		<description>Thank you for the tip, very helpfull.</description>
		<content:encoded><![CDATA[<p>Thank you for the tip, very helpfull.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

