Vous êtes sur la page 1sur 6

Some definitions and acronyms used herein...

- Scope = the range of a given, working namespace, eg, a function body vs a class body vs a package body, etc. - Feature = a property or method defined in a class body, defined for use at either Instance Level (nonstatic) or Class Level (static). Further access control is defined for features as being PUBLIC (app wide access, cross package), INTERNAL (same package), PRIVATE (ICF access only), PROTECTED (DCF access only). Note: PRIVATE and PROTECTED features are highly restricted and are meant to be accessed only via calls defined WITHIN their own class body. You cannot call PRIVATES or PROTECTEDS off an instance path without some kind of "gated" access to it already pre-programmed WITHIN THE CLASS BODY ITSELF DELIBERATELY ENABLING SUCH ACCESS. You have to "pre-program" access to them from within either an ILC or CLC that resides within an ILF or CLF of the SAME CLASS. - Immediate Class Family = ICF, is the namespace scoped to a class and its own instances, no subclasses. Features defined to this scope are for use only by the class and it's own instances, not its subclasses or their instances. This is the PRIVATE scope. Access only via gated call from an ILF or CLF. - Distant Class Family = DCF, is the namespace scoped to a class, its own instances, and any and all subclasses of it and all their instances. Features defined to this scope are for use by the class, its instances, its subclasses and their instances. Thus DCF includes ICF scope. Whether the feature is class level (static) or instance level, it is usable across the subclass range of a given class and its subclasses. This is the PROTECTED scope. Access only via gated call from an ILF or CLF. NB: PRIVATE and PROTECTED features are meant to be highly restricted things. Since instances are necessarily created OUTSIDE the context of their originating class - literally the call to instantiate them is made necessarily within ANOTHER class entirely. Subsequently any calls that an instance makes is considered originating "out of class" because that instance literally resides OUT OF CLASS because of WHERE it was instantiated.

- Instance Level Feature = ILF, a property or method defined in a class body, NOT as a STATIC and intended for use by instances. Intrinsically usable by those instances on the instance path call (see IPC, below), ie, an instance can always access an ILF. The ILF is where "gatedcalls" are defined for access to PRIVATE and PROTECTED features, whereby a PUBLIC or INTERNAL feature is defined with a call to a given PRIVATE or PROTECTED feature of the same class. This enables an instance of the class to use those PRIVATE or PROTECTED features "by proxy" through a gated PUBLIC or INTERNAL call. This is what an Instance Level Call is, see below. - Class Level Feature = CLF, a property or method defined in a class body, as STATIC and NOT intended for use by instances, but directly off the class level reference. Usable on the Class identifier. See CLC below. - Instance Level Call = ILC, feature access attempt occuring WITHIN the code body of any ILF. This is a PRE-PROGRAMMED feature access usually written to access PRIVATE or PROTECTED features. This is the only place where a PRIVATE or PROTECTED feature can be accessed. ILCs can, of course, also access any PUBLIC or INTERNAL features accordingly. The ILC is the calling of a function FROM WITHIN A FUNCTION DEFINED AS NON-STATIC IN A CLASS BODY . - Class Level Call = CLC, feature access attempt occuring WITHIN the code body of any CLF. CLCs can access PRIVATE and PROTECTED features as well as PUBLICS and INTERNALS. The CLC is the calling of a function FROM WITHIN A FUNCTION DEFINED AS STATIC IN A CLASS BODY . - Instance Path Call = IPC, feature access attempt made using a call qualified to an instance identifier. These calls necessarily are made OUTSIDE the scope of the instance's class body and are thus considered OUT-OF-CLASS calls, even though it is using an an instance of that class, which necessarily are instantiated by ANOTHER CLASS altogether. Thus, instances necessarily reside OUTSIDE the scope of their originating class and so too are calls made on the instance identifier. An IPC is NOT THE SAME as an ILC. ILCs actually are written INSIDE its originating class body. It is easy to confuse the two because a class instance is involved in both examples. It boils

down to WHERE the call to the feature originates - feature access attempts are always made from some class body. IPCs cannot make calls to PRIVATE or PROTECTED features of any class, nor any feature defined as STATIC. IPCs can make calls to features defined as PUBLIC (across packages) or INTERNAL (across classes, within package). - Class Path Call = CPC, feature access attempt made using a call qualified to an class identifier. These calls necessarily are made OUTSIDE the scope of the originating class body and are thus considered OUT-OF-CLASS calls, even though it is using a feature of that class. An IPC is NOT THE SAME as an ILC. ILCs actually are written INSIDE its originating class body. //------------------end definitions---------------// So An instance may only ever access an internal or public feature from "the instance path", because instances themselves necessarily live OUTSIDE their class of origin's scope, but they CAN execute within that scope IF AND ONLY IF they are PREPROGRAMMED to do so. This means that any PRIVATE or PROTECTED features of a given class can only be accessed from code calls WRITTEN WITHIN THAT SAME CLASS FILE ITSELF. That is, you would PRE-code access to any PRIVATE or PROTECTED ahead of time WHEN YOU CODE ITS CLASS OF ORIGIN. The only way PRIVATES or PROTECTEDS can ever be fired off is from calls made within the class file itself, from either "instance level" or "class level" functions therein. PUBLIC or INTERNAL function within that same class can be make calls to the PRIVATE or PROTECTED features. Relying on an accessible function (A PUBLIC or INTERNAL) to make a call from within its body to a more restricted feature is making a gated call. Using a public or internal feature to access a private or protected feature is like using a special "GATE" to access those deeply restricted features not available off the instance path. This is how a "GATED CALL" serves the instance of a class attempting to use those more restricted features. Private restricts to Immediate Class Family (ICF) and Protected expands a bit, allowing for subclasses of

the class to access the feature. The extended subclass of a class is the Distant Class Family (DCF). So, in order for an instance to fire off a Private or Protected feature in its class, it must do so by calling a PUBLIC or INTERNAL within its class THAT IS PREPROGRAMMED to access the Private or Protected thing. Remember: an instance of one class cant call on features of another class directly. There is no dogObj.fly()! The only way you can make a gated call from an instance of one class to the restricted features of another class is through a PUBLIC or INTERNAL STATIC Class Path Call whereby that function was pre-programmed in the file to call on PRIVATE or PROTECTED features by design. Remember STATIC just means, you have to use the class name to call the feature, Class.someFunction(). Think Actionscripts Math class. Its .random() function can be called as a Class Path Call. Within the code for the .random() function may be calls to other features defined within the Math class as PRIVATE. You dont know and you dont need to know. Thats the beauty of the black box concept of encapsulation. You just need the functionality of .random() and so you call Math.random() when you need it! eg... //---STATIC FUNCTIONS the private static function here will be callable only from this class' constructor or from another class function in THIS CLASS, and the call must be made qualified TO THE CLASS ITSELF (since it's a static feature!) //---PRIVATE FUNCTIONS The only way private features can be accessed is with IN-CLASS code, not from any instance of a class. You enable instance access to a private feature by coding that access to it from within an "instance facing" feature, literally written WITHIN THE CLASS BODY THAT DEFINES THE PRIVATE FEATURE. "Instance facing" here means a feature that IS ACTUALLY callable from an instance path, which is necessarily OUTSIDE of the class that it is instantiated

from! It's wierd kind of, but instances are created in classes OTHER than their class of origin and this means they can not directly access the private or protected features defined in their very own class of origin! No calls "off the object path" from another class, even though those instances ARE OF THE SAME CLASS as the feature they are trying to access! In other words, if you are going to allow access to privates or protecteds, you must deliberately code such access calls when their class file of origin is created by writing in those calls FROM WITHIN public or internal features that will be accessable by those instances once they are made during runtime. Runtime access to private or protected features must be deliberately coded from within the instance's originating class file, before compiling. //---PROTECTED FUNCTIONS Same rules apply for protecteds as privates, but the subclass instances may also access a protected feature of a class.

Instantiate a base class from a package as an in-package entry point for all its classes. Since this file, Main.as, is IN FACT NOT IN THE SAME PACKAGE as what you're importing, the only classes that will be available to this file are classes designated as public (as the code helper shows, only public classes are available for you to instantiate from the Main.as, because it resides outside of their package environment.) Once you instantiate a public base class here you can use that base class to access all the classes in that package as needed, through the Base.as object, including it's internals et al. Should be able to call the public static, directly OFF THE CLASS, no instance required!

You can instanstiate PUBLIC and INTERNAL CLASSES ONLY, in AS3. Dynamics are bad practice and Finals well, can't be instantiated! Try it... Create an instance of TestClassPublic so you can run the instance level stuff... An instance in AS3 may only ever access PUBLIC or INTERNAL features, "in-package". "Out of package" will only allow the PUBLIC features to run from classes outside this package. Create an instance of TestClassInternal and see what happens...should be instantiable ONLY from INPACKAGE. Create an instance of TestClassPublicSub so you can run some subclass stuff... Remember too, an instance may only ever use what ITS CLASS DEFINES FOR IT TO USE. If Dog class defines bark() but no fly(), you can call dogObj.bark() but never dogObj.fly().

-javier roman -2009 -trying to make sense of oop

Vous aimerez peut-être aussi