<?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>The bAS3 Class &#187; Design Patterns</title>
	<atom:link href="http://www.brandondement.com/blog/tag/design-patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandondement.com/blog</link>
	<description>Adventures in software development</description>
	<lastBuildDate>Thu, 29 Sep 2011 23:31:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Enforcing Abstract Classes in AS3</title>
		<link>http://www.brandondement.com/blog/2009/10/27/enforcing-abstract-classes-in-as3/</link>
		<comments>http://www.brandondement.com/blog/2009/10/27/enforcing-abstract-classes-in-as3/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 19:18:40 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://www.brandondement.com/blog/?p=52</guid>
		<description><![CDATA[One of the most common criticisms of ActionScript is that it doesn&#8217;t include some of the more advance features of other object-oriented languages.  For example, Abstract classes.  Abstract classes are similar to Interfaces in that they provide a common API for: implementers of the interface or subclasses of the Abstract class.  At [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most common criticisms of ActionScript is that it doesn&#8217;t include some of the more advance features of other object-oriented languages.  For example, Abstract classes.  Abstract classes are similar to Interfaces in that they provide a common API for: implementers of the interface or subclasses of the Abstract class.  At the same time, Interfaces and Abstract classes guarantee this common API for classes from other packages to work against.  The Abstract class takes it one step beyond the Interface in that it also adds real functionality to the base class which can reused in its subclasses.</p>
<p>So if ActionScript doesn&#8217;t enforce the Abstract class, how can you guarantee that someone down the line doesn&#8217;t start abusing it?  A passable answer to this question is the seldom-used &#8220;self&#8221; keyword, as seen here:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AbstractClass<span style="color: #66cc66;">&#40;</span>self:AbstractClass<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>self <span style="color: #66cc66;">!</span>= <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Whoa!  You can't instantiate AbstractClass directly suckah!&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The drawback to this method is that it&#8217;s not enforced at compile-time.  Instead, the error will be thrown at runtime and alert the developer that they did something wrong.  Further, there&#8217;s nothing stopping the developer from then catching the error and ignoring it.  Ruh roh.  So there is no real solution that guarantees the Abstract nature of the class is respected, but at least this little warning will deter all but the most irresponsible of programmers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandondement.com/blog/2009/10/27/enforcing-abstract-classes-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

