7 Replies Latest reply on Jun 24, 2009 11:33 PM by kglad

    Doubt regarding Interfaces

    gr8momo

      Hi All,

      I know that in actionscript "Interface files cannot contain any variable declarations or assignments."

      Can anyone please tell me why this limitation? Isn't this limiting a very powerful object oriented feature?


      [I am comparing actionscript interfaces with java interfaces]


      Thanks a ton.

        • 1. Re: Doubt regarding Interfaces
          Ned Murphy Adobe Community Professional & MVP

          Can you better explain the limitations regarding "Interface files cannot contain any variable declarations or assignments." What are you calling  interface files?

          • 2. Re: Doubt regarding Interfaces
            gr8momo Level 1

            ello Ned,

             

            I am talking about interfaces in action script. Help related to this can be found under Flash Help:

             

            Learning ActionScript 2.0 in Adobe Flash -> Interfaces > About interfaces > Defining and implementing interfaces

             

            http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Liv eDocs_Parts&file=00000830.html

             

             

            Java Interfaces allows variables to be part of the interface. We can also have static constants. These are very helpful when the interface is implemented by classes. The class can refer to these variables. (Ex: for some predefined values.)

             


            But actionscript does not allow any variables in interfaces; only methods are allowed. There must be a valid reason for this.. was just wondering why though.

             

             

            I hope im not sounding gibberish

             

            Thanks

            • 3. Re: Doubt regarding Interfaces
              Ned Murphy Adobe Community Professional & MVP

              You know more about the topic than I do.  You just introduced me to something else I never knew about with Flash (I am also class challenged).  But in the documentation you pointed to it seems that an interface file has to be implemented using a class file, and "Classes that implement a particular interface almost always include additional methods, variables, and getter and setter methods."  The interface file appears to be only a shell, a fairly empty shell, that a class file adds functionality to.

              • 4. Re: Doubt regarding Interfaces
                gr8momo Level 1

                Right on! .. in other words its an empty class without any variables. just function prototypes. Any class that "implements" it fills up the function body.

                 

                Interfaces is a very powerful concept. We can bring out amazing designs usings them.

                One more limitation in actionscript is Multiple Inheritance. The work around to achieve it is using Interfaces. And we can bring out a much better Multiple Inheritance if there were variables/static constants allowed in Interfaces.

                 

                Anyways back to my question:

                 

                Why variables/static constants are not allowed in actionscript interfaces?

                 

                Any thoughts?

                 

                This question is more towards the architecture of Flash/actionscript. What amuses me is actionscript is derived from ECMA standard same as java. So interface behaviour should be same.

                • 5. Re: Doubt regarding Interfaces
                  kglad Adobe Community Professional & MVP

                  it's to give maximum flexibility to oop.  interface files merely list all the methods and properties that are going to be defined (implemented) in another class file.

                   

                  if you were going to create one project in flash, it would make no sense to use interface and implementation classes.  but if you create many flash projects you might start thinking about re-using some of your previous work when a new project is needed.  that's when interface/implementation classes start making sense.

                  • 6. Re: Doubt regarding Interfaces
                    gr8momo Level 1

                    I totally agree... thats the usage of interfaces.

                     

                    But then again.. (sorry im repeating it again..just to keep the chain alive)

                    My question is not to do with the benifits of interfaces or how to use them.. its more to do with why they are the way they are

                     

                    "Why arent variable/static-constant declarations allowed in actionscript interfaces???"

                     

                    Anyone?

                    • 7. Re: Doubt regarding Interfaces
                      kglad Adobe Community Professional & MVP

                      i explained that in my first sentence.