Overriding methods

This all seems very simple, and once you start designing things in any form of OO way you learn that you need to “extend” a core object and change some of the functions it implements. Generally, the “base” object (initial object) is called a “base class” or “superclass”. The object that extends it is called a “subclass”.

Subclassing is simply a general term for extending an object.

You will almost certainly run into error messages when attempting these extensions. Basically you will have to make sure the base class methods you are extending fit the following rules:

  1. NOT MARKED AS FINAL: The instance method is not declared with the final keyword in the base class. When used with an instance method, the final keyword indicates the programmer’s intent to prevent subclasses from overriding the method.
  2. NOT PRIVATE: The instance method is not declared with the private access control specifier in the base class. If a method is marked as private in the base class, there is no need to use the override keyword when defining an identically named method in the subclass, because the base class method will not be visible to the subclass.

I would add my own to this list:

  1. NOT STATIC: Static methods are both NOT INHERITED and NOT OVERRIDABLE

Adobe has put a great document together to outline this and many other things relating to inheritance.

http://livedocs.adobe.com/labs/flex3/html/help.html?content=04_OO_Programming_11.html

Leave a Reply