
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
166
|
Chapter 6: Inheritance
You should notice that the code in Example 6-1 declares five methods of the
ChatRoom class. The AvatarChatRoom class likewise declares five methods, four of
which override methods in the ChatRoom class plus onUserChangePosition( ), which
is new. Let’s take a closer look at overriding, its use and implications.
Overriding Methods and Properties
In our study of inheritance so far, we’ve covered reuse, in which a subclass uses its
superclass’s methods and properties, and extension, in which a subclass adds its own
}
}
// This code must be placed in an external file named AvatarChatRoom.as
class AvatarChatRoom extends ChatRoom {
private var avatars:Array;
// Override four of the methods of the ChatRoom class,
// excluding sendMessage( ).
public function displayMessage (userID:String, msg:String):Void {
// AvatarRoom.displayMessage( ) also invokes ChatRoom.displayMessage( ).
super.displayMessage(userID, msg);
trace("Displaying message in avatar text bubble.");
}
public function onAddUser (userID:String):Void {
// AvatarRoom.onAddUser( ) also invokes ChatRoom.onAddUser( ).
super.onAddUser(userID);
trace("Creating avatar for new user.");
}
public function onRemoveUser (userID:String):Void {
// AvatarRoom.onRemoveUser( ) also invokes ChatRoom.onRemoveUser(