Game Development Reference
In-Depth Information
Class Identifiers
Classes can use few different identifiers to determine how they are
exposed to other classes. The four available identifiers are as follows:
Public : The public attribute defines that a class can be accessed
or used from anywhere else.
Internal : The internal attribute allows a class to only be
accessed by other classes in the same package
by default,
classes are internal unless specified public, so internal does not
actually have to be used.
Dynamic : If a class is dynamic, it can have properties and methods
added to it at runtime
by default, classes are static and can only
use the properties and methods defined inside themselves.
Final : If a class is final, it cannot be extended by another class
more on this shortly will be discussed when we cover inheritance
by default, classes can be extended and are not final.
All of these identifiers can be used with each other, except that
public cannot be used with internal. Similarly, variables and meth-
ods can have their own set of identifiers used to define how they
are exposed outside the class.
Public : Like the class attribute, this denotes that a variable or
method can be accessed from anywhere, including outside the
Internal : Also similar to classes, this denotes that a variable or
method can only be accessed from inside its package.
Private : The private attribute prevents a variable or method
from being accessed outside its individual class.
Protected : A protected attribute is pretty much like private,
except that protected variables and methods can also be
accessed by classes that extend the current class (more on
inheritance shortly).
Static : If a method or variable is static, it is part of the class and
not instances of the class, meaning there is only ever one value
or functionality defined, and it is accessed via the class name
rather than an instance (i.e., MovieClip.staticVar rather than
note that static properties and
methods are not inherited by subclasses.
The first four attributes in this list cannot be used with each
other, as they would conflict, but static can be used in combination
with any one of them.
Inheritance and Polymorphism
These two concepts were touched on in brief in Chapter 1, but we
expound on them a little more here. When you need to create a
class that has the same functionality as another class, but needs
some additional properties or methods, a good option to save time
Search Nedrilad ::

Custom Search