<< Chapter < Page Chapter >> Page >

This interface declares the method named volume . Because this interface is extended by the interface named IArea , any class that implements IArea inherits the abstract method named volume and must provide a concrete definition for the method.

The file named ICircumference.as

The interface named ICircumference is very similar to the interface named IVolume . The code for this interface is provided in Listing 14 near the end of the lesson.

This interface declares the method named circumference . Once again, because this interface is extended by the interface named IArea , any class that implements IArea inherits the abstract method named circumference and must provide a concrete definition for the method.

The file named MyCircle.as

The class named MyCircle is shown in its entirety in Listing 9

The class named mycircle.

package CustomClasses{ public class MyCircle implements IArea{private var radius:Number;public function MyCircle(radius:Number){//constructor this.radius = radius;}//end constructorpublic function area():String{ return "Radius = " + radius + "\n" +"Area = " + Math.PI * radius * radius; }//end areapublic function id():String{return "Circle\n"; }//end idpublic function circumference():String{return "Radius = " + radius + "\n" + "Circumference = " + 2 * Math.PI * radius;}//end function circumferencepublic function volume():String{ //Assumes that the shape is a cylinder with a// depth of ten units. return "Radius = " + radius + "\n" +"Depth = 10\n" + "Volume = " + 10 * Math.PI * radius * radius;}//end area}//end class }//end package

Inherits four abstract methods

As you can see, this class implements the interface named IArea , causing it to inherit the following abstract methods :

  • area
  • id
  • circumference
  • volume

The area and id methods are declared in the IArea interface and are inherited directly into the MyCircle class.

The circumference and volume methods are declared in the interfaces named ICircumference and IVolume , both of which are extended by the IArea interface. Therefore, the MyCircle class inherits those abstract methods by way the IArea interface.

Concrete definitions for four methods

Listing 9 provides concrete versions of the four inherited abstract methods. As a practical matter, this amounts to overriding inherited abstract methods.Note however, that unlike the case of overriding a concrete method inherited from a class, the keyword override is not required when overriding an abstract method inherited from an interface.

Other than the fact that this class implements an interface and overrides inherited abstract methods, there is nothing in Listing 9 that should be new toyou.

The file named MyRectangle.as

The class named MyRectangle is defined in Listing 16 near the end of the lesson. This class is very similar to the MyCircle class shown in Listing 9. As with the MyCircle class, it implements the IArea interface. Therefore, it inherits and overrides the same four abstract methods shown in the above list .

Run the program

I encourage you to run this program from the web. Then copy the code from Listing 10 through Listing 16. Use thatcode to create a Flex project. Compile and run the project. Experiment with the code, making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as theydo.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask