<?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: ActionScript 3 – No Private Constructor???</title>
	<atom:link href="http://gorillajawn.com/wordpress/2007/05/21/actionscript-3-%e2%80%93-no-private-constructor/feed/" rel="self" type="application/rss+xml" />
	<link>http://gorillajawn.com/wordpress/2007/05/21/actionscript-3-%e2%80%93-no-private-constructor/</link>
	<description>Enterprise Software Consultant</description>
	<lastBuildDate>Mon, 15 Mar 2010 20:02:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ciprian</title>
		<link>http://gorillajawn.com/wordpress/2007/05/21/actionscript-3-%e2%80%93-no-private-constructor/comment-page-1/#comment-21203</link>
		<dc:creator>Ciprian</dc:creator>
		<pubDate>Tue, 24 Nov 2009 17:10:38 +0000</pubDate>
		<guid isPermaLink="false">http://ectropic.com/wordpress/?p=4#comment-21203</guid>
		<description>I&#039;m looking (for a while) to build a true singleton, one that is not instantiable at compile time. These work-arrounds that throw errors may be fine if you really don&#039;t have a choice but I don&#039;t like them. I will keep searching for the solution until I find it.</description>
		<content:encoded><![CDATA[<p>I&#8217;m looking (for a while) to build a true singleton, one that is not instantiable at compile time. These work-arrounds that throw errors may be fine if you really don&#8217;t have a choice but I don&#8217;t like them. I will keep searching for the solution until I find it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Feminella</title>
		<link>http://gorillajawn.com/wordpress/2007/05/21/actionscript-3-%e2%80%93-no-private-constructor/comment-page-1/#comment-17</link>
		<dc:creator>Eric Feminella</dc:creator>
		<pubDate>Tue, 22 May 2007 03:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://ectropic.com/wordpress/?p=4#comment-17</guid>
		<description>It is possible to create pseudo-abstract classes as well as true Singletons in ActionScript 3 via inner classes. Below is how I would typically implement a pseudo-abstract class as well as a true Singleton:

Abstract Example:
package {
public class Abstract {
public function Abstract(access:Private) {
  if(access == null){
      throw new Error(&quot;NullPointerException...&quot;);
  }
}
protected static final function getAccess():Private{
   return new Private();
}
}
}
class Private{}

Implementation:
package {
public class SubClass extends Abstract {
    public function SubClass(){
         super( getAccess() );
    }
  }
}

For details visit:http://www.ericfeminella.com/blog/2007/01/16/pseudo-abstract-classes-in-as3/

Singleton Example:
package {
public class SingletonExample { 
    private static var instance:SingletonExample;
    public function SingletonExample (access:Private) {
    if(access == null){
         throw new Error(&quot;NullPointerException...&quot;);
    }
    instance = this;
  }
  public static function getInstance() : SingletonExample {
     if (instance == null)
     { 
          instance = new SingletonExample( new Private );
     }
     return instance;
  }
}

Hope this helps.

- Eric

class Private {}</description>
		<content:encoded><![CDATA[<p>It is possible to create pseudo-abstract classes as well as true Singletons in ActionScript 3 via inner classes. Below is how I would typically implement a pseudo-abstract class as well as a true Singleton:</p>
<p>Abstract Example:<br />
package {<br />
public class Abstract {<br />
public function Abstract(access:Private) {<br />
  if(access == null){<br />
      throw new Error(&#8220;NullPointerException&#8230;&#8221;);<br />
  }<br />
}<br />
protected static final function getAccess():Private{<br />
   return new Private();<br />
}<br />
}<br />
}<br />
class Private{}</p>
<p>Implementation:<br />
package {<br />
public class SubClass extends Abstract {<br />
    public function SubClass(){<br />
         super( getAccess() );<br />
    }<br />
  }<br />
}</p>
<p>For details visit:http://www.ericfeminella.com/blog/2007/01/16/pseudo-abstract-classes-in-as3/</p>
<p>Singleton Example:<br />
package {<br />
public class SingletonExample {<br />
    private static var instance:SingletonExample;<br />
    public function SingletonExample (access:Private) {<br />
    if(access == null){<br />
         throw new Error(&#8220;NullPointerException&#8230;&#8221;);<br />
    }<br />
    instance = this;<br />
  }<br />
  public static function getInstance() : SingletonExample {<br />
     if (instance == null)<br />
     {<br />
          instance = new SingletonExample( new Private );<br />
     }<br />
     return instance;<br />
  }<br />
}</p>
<p>Hope this helps.</p>
<p>- Eric</p>
<p>class Private {}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Peters</title>
		<link>http://gorillajawn.com/wordpress/2007/05/21/actionscript-3-%e2%80%93-no-private-constructor/comment-page-1/#comment-7</link>
		<dc:creator>Keith Peters</dc:creator>
		<pubDate>Mon, 21 May 2007 10:07:32 +0000</pubDate>
		<guid isPermaLink="false">http://ectropic.com/wordpress/?p=4#comment-7</guid>
		<description>Yes, this has been talked about for the last year and a half, extensively. There are a few workarounds. The one given above is that it only throws a runtime error. There&#039;s another technique using instance of a helper class that is passed into the constructor. Since the helper class is only available to the file itself, you will get a compile error if you try to instantiate it using the constructor. I&#039;m sure you can dig up several examples of this with a quick search. The problem with that one though, is that you can still get around it by passing in null to the constructor.</description>
		<content:encoded><![CDATA[<p>Yes, this has been talked about for the last year and a half, extensively. There are a few workarounds. The one given above is that it only throws a runtime error. There&#8217;s another technique using instance of a helper class that is passed into the constructor. Since the helper class is only available to the file itself, you will get a compile error if you try to instantiate it using the constructor. I&#8217;m sure you can dig up several examples of this with a quick search. The problem with that one though, is that you can still get around it by passing in null to the constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jonr</title>
		<link>http://gorillajawn.com/wordpress/2007/05/21/actionscript-3-%e2%80%93-no-private-constructor/comment-page-1/#comment-5</link>
		<dc:creator>jonr</dc:creator>
		<pubDate>Mon, 21 May 2007 08:14:03 +0000</pubDate>
		<guid isPermaLink="false">http://ectropic.com/wordpress/?p=4#comment-5</guid>
		<description>Thanks for the comment Gerald!  

The workaround you provided is sufficient.  Although, I do still find it annoying that I cannot enforce the access limitation at compile time, and can only throw an error during runtime.

Coming from a Java development background, this limitation of ActionScript 3 surprised me.  Although, I do understand it is a limitation to make ActionScript 3 compliant with the ECMA Script specification.</description>
		<content:encoded><![CDATA[<p>Thanks for the comment Gerald!  </p>
<p>The workaround you provided is sufficient.  Although, I do still find it annoying that I cannot enforce the access limitation at compile time, and can only throw an error during runtime.</p>
<p>Coming from a Java development background, this limitation of ActionScript 3 surprised me.  Although, I do understand it is a limitation to make ActionScript 3 compliant with the ECMA Script specification.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerald Yeo</title>
		<link>http://gorillajawn.com/wordpress/2007/05/21/actionscript-3-%e2%80%93-no-private-constructor/comment-page-1/#comment-4</link>
		<dc:creator>Gerald Yeo</dc:creator>
		<pubDate>Mon, 21 May 2007 07:57:33 +0000</pubDate>
		<guid isPermaLink="false">http://ectropic.com/wordpress/?p=4#comment-4</guid>
		<description>The work around would be this:

package com.flashobscura{
	public class SingletonDemo {
		private static var INSTANCE:SingletonDemo = null;
		private static var ALLOWINSTANTIATION:Boolean = false;
		
		public function SingletonDemo() {
			if (getQualifiedClassName(super) == &quot;com.flashobscura::SingletonDemo&quot; ) {
				if (!ALLOWINSTANTIATION) {
					throw new Error(&quot;Error: Instantiation failed: Use SingletonDemo.getInstance() instead of new.&quot;);
				}
				else {
					// do initialisation
				}
			}
			
		}
		
		public static function getInstance():SingletonDemo {
			if (INSTANCE == null) {
				ALLOWINSTANTIATION = true;
				INSTANCE = new SingletonDemo();
				ALLOWINSTANTIATION = false;
			}
			return INSTANCE;
		}
	}
}</description>
		<content:encoded><![CDATA[<p>The work around would be this:</p>
<p>package com.flashobscura{<br />
	public class SingletonDemo {<br />
		private static var INSTANCE:SingletonDemo = null;<br />
		private static var ALLOWINSTANTIATION:Boolean = false;</p>
<p>		public function SingletonDemo() {<br />
			if (getQualifiedClassName(super) == &#8220;com.flashobscura::SingletonDemo&#8221; ) {<br />
				if (!ALLOWINSTANTIATION) {<br />
					throw new Error(&#8220;Error: Instantiation failed: Use SingletonDemo.getInstance() instead of new.&#8221;);<br />
				}<br />
				else {<br />
					// do initialisation<br />
				}<br />
			}</p>
<p>		}</p>
<p>		public static function getInstance():SingletonDemo {<br />
			if (INSTANCE == null) {<br />
				ALLOWINSTANTIATION = true;<br />
				INSTANCE = new SingletonDemo();<br />
				ALLOWINSTANTIATION = false;<br />
			}<br />
			return INSTANCE;<br />
		}<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
