After spending a good part of Christmas tinkering around with AS and Flex, I’ve decided to stop trying to put getters and setters around member variables unless needed. This may make my Java friends recoil in horror, but I think it makes sense.
When it comes to getters and setters, Java and AS are quite different, in that getters and setters are part of the core ECMAScript language, whereas in Java, getters and setters are done through a naming convention.
In Java, it is almost never a good idea to make member variables public. If you do decide to make member variables public and then later want to change the interface to use getter/setter functions, you will have to modify all callers of your interfaces, which is onerous at best and in many cases, not possible (expecially when you are creating code that is used by other people).
Meanwhile, in ECMAScript, the externally visible interface doesn’t change when I go from a member variable to a getter/setter and back again. In some sense, the interface hiding is already accomplished in the language. Creating public member variables is “safe” in this sense.
Perhaps this is already obvious to all the AS-heads out there, but it took me a bit of time to get used to the concept. Now that I’ve flipped this bit in my head, I’m going to go ripping out all extraneous getters and setters from my code!