2 Replies Latest reply on Mar 15, 2008 8:15 AM by TrAvIkK

    Storing instances

    TrAvIkK
      Hi.

      I'm currently developing multi-actionscript-file application, object oriented.
      I want to store instances of clasess, so I will have access to instance of class "ABC" (for i.e.) everywhere.
      I was thinking about static class, which will have ArrayList object, with every instance i want to. I think it's better than having a singleton in every class.

      What do you think?
        • 1. Re: Storing instances
          Sreenivas R Adobe Employee
          Without knowing more context info it is difficult to comment. The missing information is where this list would be accessed and what action would be taken on these objects in the ArrayList.

          I see following problems with this approach :

          If the static ArrayList is going to carry instances of class A, class B and class C (etc..) won't it lead to if..else cases to figure out which object belongs to which class?

          If a object from new class D is added would it require updates to all these if...else cases ?

          Would it be better to use a Dictionary where key is the class and vlaue is array of objects of instances of that class?

          Or is it based on the assumption that all these object instances will implement a certain interface and problems 1 and 2 stated above doesn't arise?
          • 2. Storing instances
            TrAvIkK Level 1
            Well, as far as now I've coded 2-D array. Example:
            Array {
            Array { name, instance },
            Array { name, instance },
            ...
            }

            And to get an instance i've got a searching-loop.
            Code looks like this: http://phpfi.com/302813

            Also, have I correctly used form of returned type in getSingleton ? And in addSingleton for singleton variable?