Hey,

It's not considered good practice to use singetons.  For reasons why, here's
a good article:
http://blogs.msdn.com/scottdensmore/archive/2004/05/25/140827.aspx

I don't think the protected keyword exists in AS2, but if you have AS3, I'd
trying using the protected keyword for the singleton's superclass
constructor.  I'd recommend trying this as an experiment only.

-vf

----- Original Message ----- From: "Christophe Herreman" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, March 23, 2006 7:38 AM
Subject: [Bulk] [Flashcoders] Extending a singleton


Hi guys,

I was wondering if anyone of you ever had a situation where it would be
good to extend a singleton. The first question is: Is it good practice or
should it be avoided at all cost?

Anyway, I have been trying to extend one, but the problem is that instance
variables are not accessible in the class that extends the singleton (and
which is also a singleton).

So for instance, take a class A that has a "properties" instance variable
that holds key/value pairs. That var is initialized in the constructor.

A.getInstance() gives me the single instance.

B extends A, and B.getInstance() gives me the single instance of B. But
since it extends A, A's constructor is called (although it is private, a
camouflaged protected in AS2) and the properties var is instantiated
again. Get the picture? B will have a properties instance var but it will
not be the same as the one in the singleton of A.

Am I overlooking something very obvious here or is this actually hard to
accomplish? I changed it from inheritance to using A.getInstance()
internally which works; but now I have to add wrapper methods for every
method in A/ /I want to make available.

thx in advance,
Christophe
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to