Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / Database concepts.pdf
Скачиваний:
29
Добавлен:
12.05.2015
Размер:
6.96 Mб
Скачать

Type Inheritance

The second line specifies lineitems_table as the storage table for the lineitems attributes of all of the purchase_order objects in purchase_ order_table.

A convenient way to access the elements of a nested table individually is to use a nested cursor.

See Also:

Oracle9i Database Reference for information about nested cursors

Oracle9i Application Developer’s Guide - Object-Relational Features for more information about using nested tables

Type Inheritance

An object type can be created as a subtype of an existing object type. A single inheritance model is supported: the subtype can be derived from only one parent type. A type inherits all the attributes and methods of its direct supertype. It can add new attributes and methods, and it can override any of the inherited methods.

Figure 13–1 illustrates two subtypes, Student_t and Employee_t, created under

Person_t.

Figure 13–1 A Type Hierarchy

Person_t

Student_t

Employee_t

PartTimeStudent_t

Furthermore, a subtype can itself be refined by defining another subtype under it, thus building up type hierarchies. In the preceding diagram, PartTimeStudent_t is derived from subtype Student_t.

FINAL and NOT FINAL Types

A type declaration must have the NOT FINAL keyword, if you want it to have subtypes. The default is that the type is FINAL; that is, no subtypes can be created for the type. This allows for backward compatibility.

Object Datatypes and Object Views 13-13

Type Inheritance

Example of Creating a NOT FINAL Object Type

CREATE TYPE Person_t AS OBJECT ( ssn NUMBER,

name VARCHAR2(30),

address VARCHAR2(100)) NOT FINAL;

Person_t is declared to be a NOT FINAL type. This enables definition of subtypes of Person_t.

FINAL types can be altered to be NOT FINAL. In addition, NOT FINAL types with no subtypes can be altered to be FINAL.

NOT INSTANTIABLE Types and Methods

A type can be declared to be NOT INSTANTIABLE. This implies that there is no constructor (default or user-defined) for the type. Thus, it is not possible to construct instances of this type. The typical use would be define instantiable subtypes for such a type, as follows:

CREATE TYPE Address_t AS OBJECT(...) NOT INSTANTIABLE NOT FINAL;

CREATE TYPE USAddress_t UNDER Address_t(...);

CREATE TYPE IntlAddress_t UNDER Address_t(...);

A method of a type can be declared to be NOT INSTANTIABLE. Declaring a method as NOT INSTANTIABLE means that the type is not providing an implementation for that method. Furthermore, a type that contains any non-instantiable methods must necessarily be declared NOT INSTANTIABLE.

For example:

CREATE TYPE T AS OBJECT

(

x NUMBER,

NOT INSTANTIABLE MEMBER FUNCTION func1() RETURN NUMBER ) NOT INSTANTIABLE;

A subtype of a NOT INSTANTIABLE type can override any of the non-instantiable methods of the supertype and provide concrete implementations. If there are any non-instantiable methods remaining, the subtype must also necessarily be declared

NOT INSTANTIABLE.

A non-instantiable subtype can be defined under an instantiable supertype.

Declaring a non-instantiable type to be FINAL is not allowed.

See Also: PL/SQL User’s Guide and Reference

13-14 Oracle9i Database Concepts

Соседние файлы в папке Oracle selected docs