The singleton pattern is dangerous, as are global variables.
The problem is, you can't reuse any of the singleton's users without using
the singleton.
I guess, that's the reason why Brett was asking for a poor man's
implementation of IoC

Cheers,
Ralf.



On 2/7/07, Troy Gilbert < [EMAIL PROTECTED]> wrote:

  That's usually the point of the singleton pattern, that it provides a
global access point for a variable (as well as enforcing a single instance
of a class). Essentially, singleton hijacks a language's type system to use
it to deliver globals.

Of course, in languages like C++ I kinda consider this on par with using
globals and normally prefer something like a monostate object where many
would use a singleton. But, since ActionScript doesn't actually have global
objects, singleton is pretty useful for attaining that.

Perhaps I've missed the guts of your question, but if you create a class
that follows the singleton pattern, you'd have a "getInstance()" static
method. To access your instance you just need to import your singleton class
wherever you need it and then use MyClass.getInstance() to access the
singleton. You'd have to import the class regardless if you wanted to
*access* the singleton, so I'm not quite sure where the disconnect is in
your question...

Troy.


On 2/6/07, rumpleminzeflickr <[EMAIL PROTECTED] > wrote:
>
>   Hi there,
>
> I have a main app, with a lot of sub custom components.
>
> I've created a singleton class that i'm using as a controller.
>
> what I want to know is, do I have to define access to that singleton
> class in every custom component, or is there some way to 'pass' the
> instance of it down the line and make it available to all.
>
> Sorry if this is a dumb question, I tried searching without an answer
> so far :(
>
> Brett
>
>



--
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany
Phone +49 (0) 221 530 15 35

Reply via email to