10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 1-13. QuadPets.as (continued)<br />

}<br />

}<br />

}<br />

trace("Superclass:Pet Sound");<br />

Any class that uses the extends statement to declare a class inherits the class characteristics<br />

it extends. The class that’s extended is the superclass (or parent). The class<br />

that extends another class is the subclass. Both the Dog and Cat classes are subclasses<br />

of the QuadPets class. They inherit all the superclass’ functionality. To see how that<br />

happens, we’ll have to first create the two subclasses.<br />

Example 1-14. Dog.as<br />

package<br />

{<br />

public class Dog extends QuadPets<br />

{<br />

public function Dog( ):void<br />

{<br />

}<br />

public function bark( ):void<br />

{<br />

trace("Dog class: Bow wow");<br />

}<br />

}<br />

}<br />

Example 1-15. Cat.as<br />

package<br />

{<br />

public class Cat extends QuadPets<br />

{<br />

public function Cat( ):void<br />

{<br />

}<br />

public function meow( ):void<br />

{<br />

trace("Cat class: Meow");<br />

}<br />

}<br />

}<br />

To see how the Dog and Cat classes inherit the operations of the superclass, the<br />

TestPets class simply invokes the single method (makeSound) from the superclass. As<br />

you can see from the Dog and Cat classes, no such method can be seen in their construction,<br />

and so you can see that it must have originated in the QuadPets class.<br />

26 | Chapter 1: Object-Oriented Programming, <strong>Design</strong> <strong>Patterns</strong>, and <strong>ActionScript</strong> <strong>3.0</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!