Tuesday, May 27, 2008

Inheritance

In any object-oriented system type inheritance is essential. Oracle provides the capability for the single-type inheritance model where a subtype inherits all its supertype’s attributes and methods (Oracle, 2002a). Additionally, a subtype can add new attributes and methods and override inherited methods (Oracle, 2002a, p. 6).

create type PERSON_TY as object(name varchar2(25),birthdate date
member function AGE() return number, member function PRINTME() return varchar2) not final;

This syntax creates a root type of an object hierarchy – what’s new here is the use of “NOT FINAL”. To create a subtype the following syntax can be used (Oracle, 2002a, p. 6):
create type EMPLOYEE_TY under PERSON_TY (
salary number,
member function WAGES() return number,
overriding member function PRINTME() return varchar2);

The type EMPLOYEE_TY inherits all the attributes and methods from the supertype PERSON_TY. In this example, the attribute salary and the function wages have been added. The function PRINTME is overridden to return some other sort of value as must be defined later in a “create or replace type body” construct as detailed in the Implementing Methods section of this paper.

No comments: