3 Replies Latest reply on Nov 14, 2011 8:44 PM by highlightscript

    java and flex getters and setters

    194642537 Level 1

      Hi All,

       

         I read that the difference between flex and java getter and setter is that it provides an interface and the underlying implementation can be changed.

       

       

         Can anybody please help me understand this as a did not get the concept completly.

       

      Thanks

        • 1. Re: java and flex getters and setters
          drkstr_1 Level 4

          Java technically does not have what is usually referred to as "getters and setters". Instead, you just use a standard method to get and set private data.

           

          Both java style setters (aka functions) and AS3 style setters can be used to define an interface, so functionally, there is no difference between the two.

          • 2. Re: java and flex getters and setters
            Ansury Level 3

            Java getters & setters: http://2.bp.blogspot.com/-LA3h7GtZNEY/TWo4-cLwbsI/AAAAAAAAAcY/91Cu5cV1fCY/s1600/Youre%2Bdoing%2Bit%2Bwrong.jpg

             

             

            Java does getters & setters rather poorly - they must be generated or written manually, because they're just regular method calls.

             

            Flex/AS getters & setters are implicit - this means you should simply use public variables, and only write a get or set function as needed.  This is because a public variable and a public getter/setter function are accessed exactly the same way in ActionScript:

             

            value = "whatever";  //Set syntax in AS, regardless whether it's a public var or set function

             

            setValue("whatever"); //Set syntax in Java if using setter function

            value = whatever; //For a Java public variable you'd instead have to write this

             

            ActionScript's implicit getter and setter system (which is built into the language, unlike Java's kludgy method) lets you avoid cluttering your classes with "just in case" boilerplate getter & setter methods (Java), while you still retain the ability to later add special get/set logic if needed (without having to change the syntax of all your external references to use a function).

             

            Google "implicit getters and setters" for more about ActionScript's superior getter/setter implementation.  (By the way, I'm not bashing Java, I'm a long time Java dev and a big supporter of Java in general.  But I give credit where credit is due, AS wins this round easy.)

            • 3. Re: java and flex getters and setters
              highlightscript Level 1

              Java has only Explicit getters but actionscript can have both implicit and Explicit getters