AS3 is not a prototype language

On 2/9/06, Michael Hansen <[EMAIL PROTECTED]> wrote:
AS3 has some pretty interesting constructs, and private constructors is not one of them. Don't be fooled - it's not java. I can recommend reading up on the as3 pdf.

A couple of months ago I hit that same stumbling block, i.e. "what! no private constructors?!"

I what follows is a response from zwetan posted on the Adobe labs forum:

zwetan writes:

here are common cases where *other* languages need private constructors:

- classes containing only static utility methods
- classes containing only constants
- type safe enumerations
- singletons


in AS3 with the actual implementation of the ECMAScript 4 spec
you don't need private constructors to implement all that

for cases:
- classes containing only static utility methods
- classes containing only constants

package foobar
{

class blah
{

function blah() //internal
{
}

public const test:String = "test";

public static function utility():String
{
return "hello world";
}
}
}

the constructor "blah" is by default internal to the package,
you can not instanciate it outside of the package

but by declaring the constant and/or static members public
you can access them outside from the package.

(you don't even need to define a constructor )

check the prog_actionscript3.pdf page 43

class ConstExample
{
static const EXAMPLE_STATIC:String = "Global access";
public const EXAMPLE_PUBLIC:String = "Public access";
private const EXAMPLE_PRIVATE:String = "Class access";
}


for the singletons case it's almost the same,
especially if you want to have a constructor to initialize it

-----------------------
package foobar
{

class Singleton() //internal
{
function Singleton() //package scope internal constructor
{
}

public var someProperty:String = "someProperty";

public function someMethod():String
{
return "someMethod"
}
}
}
-----------------------
package foobar
{

public const MySingleton:Singleton = new Singleton();

}
-----------------------

you can only instanciate the Singleton constructor inside its package,
not outside because it IS internal,
and making it const and public you're sure it gonna be
globally accessible and instancied only once.

You don't need private constructor in prototype-based language
because you can directly have an object

http://en.wikipedia.org/wiki/Singleton_pattern
" In a prototype-based programming language, where objects but not classes
are used, a "singleton" simply refers to an object without copies or that is
not used as the prototype for any other object."

zwetan







On 2/10/06, Johannes Nel <[EMAIL PROTECTED]> wrote:
abstract classes i am not expecting, private constructers i certainly hope for


On 2/9/06, Carlos Rovira <[EMAIL PROTECTED] > wrote:
Hi,

I was trying to migrate some classes from AS2 to AS3 and notice that can't mark the class constructor as private. Is that correct or there's a workaround? if not have plans to implement private constructors.

and abstract classes?

Thanks in advance.

--
::| Carlos Rovira
::| http://www.carlosrovira.com

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS






--
j:pn



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS






--
j:pn


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to