Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming

> ## Overriding methods

> A class definition that inherits from another class can define a method to override a `PUBLIC` or `PROTECTED` method in its class hierarchy as long as it is not marked `FINAL`. The method must have the same method name, access modifier, return type, and number of parameters, and each corresponding parameter must be of the same mode (`INPUT`, `OUTPUT`, or `INPUT-OUTPUT`) and of the same data type as the method it is overriding. However, a `PUBLIC` subclass method can override a `PROTECTED` super class method, if you want. The overriding method must also use the `OVERRIDE` keyword to assure the compiler that the override is intended. The method that is overridden does not need to be in the immediate super class. If Progress does not find a matching method in the immediate super class in the hierarchy, it searches further up the hierarchy. If no matching method is found in the hierarchy then Progress returns a compile-time error.

> Method overriding is the means by which the language supports polymorphism. In some languages it is valid to define multiple methods with the same name but different signatures, a practice known as overloading. Overloading of methods is not supported in this release of OpenEdge. If a method has the same name as another method further up its class hierarchy, but the signatures do not match, Progress returns a compile-time error.

> Once a method has been overridden, all invocations of that method call the method in the bottom-most subclass where it is defined. There is no direct access to the super class's version of an overridden method from outside the class. However, an overridden method in a subclass can invoke the same method in its super class using the `SUPER` system reference along with the method name. For more information, see the "Calling a super class method" section.

> If the super class's method is defined as `PRIVATE`, the method is not inherited by the subclass. If the subclass defines a method of the same name, it is not overriding the super class method because the super class's definition is not available to the subclass. In this case, the subclass method is entirely independent of the super class method. Because of this, it does not matter whether the methods match in their return type, access modifier, or parameters. Also in this case, use of the `OVERRIDE` keyword on the method is not appropriate.

> If the super class's non-private method is defined as `FINAL`, no subclass can override that method. The compiler returns an error if you attempt to compile a subclass that has a method with the same name as a `FINAL` method in a super class, regardless if the signatures match.

> The following sample class references and extends the sample subclass, `acme.myObjs.CustObj` (see the "Sample classes" section). This sample extension overrides the `GetCustomerName( )` method to return an E-mail address with the customer name:

>     CLASS acme.myObjs.NECustomer INHERITS acme.myObjs.CustObj:
>         DEFINE PROTECTED TEMP-TABLE ttEmail NO-UNDO
>             FIELD CustNum LIKE Customer.CustNum
>             FIELD Email AS CHARACTER.
>         /* Code to initialize ttEmail */
>         ...
>         /* Override method to always get customer name and email */
>         METHOD PUBLIC OVERRIDE CHARACTER GetCustomerName
>                                          (INPUT piCustNum AS INTEGER):
>             DEFINE VARIABLE CustName AS CHARACTER NO-UNDO.
>             CustName = SUPER:GetCustomerName(INPUT piCustNum).
>             FIND FIRST ttEmail WHERE ttEmail.CustNum = piCustNum.
>             RETURN CustName + ";" + ttEmail.Email.
>         END METHOD.
>     END CLASS.

> This extension adds a new temp-table to provide the E-mail address, which can be initialized by another method, or even the constructor for `acme.myObjs.NECustomer` (see the following section). Note that only methods can be overridden, constructors and destructors are implicitly `FINAL` and cannot be overridden in a subclass.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095