Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 151

Programming actionscript 3.0
Table of Contents

Advertisement

}
}
The interface defines two methods: the
area of the shape, and the
shape's properties.
We also want to know the distance around the perimeter of each shape. However, the
perimeter of a circle is called the circumference and it's calculated in a unique way, so the
behavior diverges from that of a triangle or a square. Still there is enough similarity between
triangles, squares, and other polygons that it makes sense to define a new interface class just
for them: IPolygon. The IPolygon interface is also rather simple, as shown here:
package com.example.programmingas3.geometricshapes
{
public interface IPolygon extends IGeometricShape
{
function getPerimeter():Number;
function getSumOfAngles():Number;
}
}
This interface defines two methods common to all polygons: the
that measures the combined distance of all the sides, and the
adds up all the interior angles.
The IPolygon interface extends the IGeometricShape interface, which means that any class
that implements the IPolygon interface must declare all four methods—the two from the
IGeometricShape interface, and the two from the IPolygon interface.
Defining the shape classes
Once you have a good idea about the methods common to each type of shape, you can define
the shape classes themselves. In terms of how many methods you need to implement, the
simplest shape is the Circle class, shown here:
package com.example.programmingas3.geometricshapes
{
public class Circle implements IGeometricShape
{
public var diameter:Number;
public function Circle(diam:Number = 100):void
{
this.diameter = diam;
}
public function getArea():Number
getArea()
method, which assembles a text description of the
describe()
method, which calculates and returns the
getPerimeter()
getSumOfAngles()
Example: GeometricShapes
method
method that
151

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents