Game Development Reference
In-Depth Information
Here is an example to specify that a class implements certain interface:
public class Vehicle extends Sprite implements PhysicsItem
Now why would you want to define a class that has no properties and no method
implementations except its signature?
Here is a good example as to why. Imagine you have created a class that simulates
physics in your game. It means depending on the physical attributes of objects in
your game; your physics engine will apply gravity, collision reactions among objects,
and so forth.
Now, the various objects may have its own inheritance structure while your physics
engine should be generic enough to deal with objects no matter what the specific
object's inheritance looks like.
But your physics engine demands certain properties and methods to exist in each
of the object that it has to deal with. You can say all objects must conform to an
interface so that the physics engine can interact with it. The interface would be to
get mass or weight of an object, get frictional properties, adjust the velocity and
acceleration on these objects and so on.
A clean object-oriented way to handle this would be to create an interface and then
have all the objects that need to be controlled by the physics engine implement
the interface.
A class can inherit only from one parent class, but can implement several interfaces.
Static properties and methods
ActionScript 3 also allows us to define a static method or a class property by using
the static keyword in its declaration. The static allows you to use or access the
properties or methods without having to create an object for a class.
Below are some sample declarations:
private static const DELTA:int = 10;
protected static var MAX_SPEED:Number = 100.0;
public static var DEFAULT_NAME:String = "Guest";
Note that just like regular (non-static) properties, static properties and methods may
be used in conjunction with scoping attributes and used for constants and variables.
However, there is one restriction that static properties and methods may not be
overridden by a subclass.
 
Search WWH ::




Custom Search