And another point: Suppose you start out making something as a public
field and then later realize you need to restrict its value in some
way. With properties, this change will make absolutely no difference
to the rest of your code. Without properties, you will have to change
every instance of "obj.myField = x" to "obj.setMyField(x)" and every
other instance of "obj.myField" to "obj.getMyField()". So it makes
this type of refactoring far easier.
Well, the idea is that you'd never mix the two syntaxes. Either every
single field uses explicit getters, or every single one uses
property-style access.
Personally I find properties (i.e., implicit getters and setters) to
be one of ActionScript's few advantages over Java as a language. (Now
if only we could have abstract classes, exception types in function
signatures, etc....)
An abstract class is just one that provides some of the implementation,
but not all of it (as distinct from an interface, which provides none of
the implementation). You can do abstract classes in AS, just name them
"AbstractButton implements Button" and then "SpecificButton extends
AbstractButton". This does require that all your coders know not to try
to use an abstract-named class directly. It's not enforced by the
language, but that's not a huge loss.
The only reason to put an exception in a method signature is to ensure
that it is checked, and I actually don't like checked exceptions. I
would like to know about exceptions, but not be forced to handle them at
compile-time -- that just leads to a lot of lazy "swallowed" exceptions,
and in a really big app you could even be forced to handle exceptions
that just aren't relevant to begin with, or for which you have no
resolution context. And for simply informing the coder about exceptions,
just include it in your documentation. AS2API allows a "@throws
ExceptionClass when blah blah blah" comment, I'm sure ASDoc and other
solutions do too.
The things *I* miss most from Java are generics, and the ability to
define constants in interfaces.
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com