mebbe I've just skipped over the part in the docs or EAS3 that explains things better.. but having to have stuff PUBLIC in a super class so I can refer to it or override it in a subclass seems crappy to me?
I'd like to hear the opinions of you people who know more about OOP than I do?
public = available from anywhere protected = available in subclass private = available only in single class definition.
A
I found this blog post after looking up protected:http://flexblog.faratasystems.com/?p=78
which in itself wasnt' very helpful to me, but a couple of the comments were enlightening:
Protected is a very important distinction. It’s not so much about the protection of the variable as it is protection of the API. Typically you see this to describe the access levels:
public : anyone protected: pacakge and subclasses private: this class (and it’s inner/nested classes)
However, better to think like this:
public: public API protected: implementation API private: private implementation API
Recast the terms like this, and it becomes quite obvious why the different levels. A protected member is tied to the implementation of a class that subclasses (i.e. classes that share part of it’s implementation) need to be aware of, but which classes that don’t share implementation shouldn’t care about (because it’s not part of their interface). A public member should be totally detached from implementation.
In the switch to the new version of ECMAScript, the private keyword from AS2 received a new meaning in AS3. Now, with private, you can no longer access a variable in subclasses. The protected keyword works like the old private.
Certainly, if you want to let anyone use a property, you should make it public. There are situations where you want subclasses to access your variables, but not everyone.
So I think generally speaking I should move to use protected where I now use private, and only use private in very specific situations where I know method X is only to be used in that class and not in any potential subclasses.
Thanks Lith.