13.16 Table containing an abstract data type

An abstract data type can be defined as the data type of a column in a table. Tables containing abstract data types can be created.

An abstract data type provides a structure that enables complicated data that cannot be handled at all by existing data types to be handled easily. HiRDB allows users to define such a data type as an abstract data type. Creating an abstract data type involves using the definition SQL to define attributes indicating the structure and to define the operations to be performed on the values.

An abstract data type can be treated as a data type of a table, in the same manner as any other data type provided by the HiRDB system, such as the numeric and character types.

Figure 13-25 shows the data structure of a table containing an abstract data type. In this figure, the EMPLOYEE column of the STAFF_TABLE is set to abstract data type t_EMPLOYEE.

Figure 13-25 Data structure of a table containing an abstract data type

[Figure]

Organization of this section
(1) Effects of defining an abstract data type
(2) Overview of inheritance
(3) Effects of using inheritance
(4) Defining an abstract data type

(1) Effects of defining an abstract data type

(2) Overview of inheritance

(a) Inheritance

A new abstract data type can be derived from an existing abstract data type by inheriting attributes and the manipulation procedure. When this is done, the base type is called the supertype and the derived type is called a subtype. Transferring a supertype's attributes and function to a subtype is called inheritance.

The relationship between a supertype and a subtype can be expressed as a hierarchy. Therefore, a complicated concept model can also be expressed as a hierarchy using an abstract data type.

Figure 13-26 shows a hierarchical structure based on the relationship between a supertype abstract data type and a subtype. In this figure, the subtype OPERATOR is derived from the abstract data type EMPLOYEE.

Figure 13-26 Hierarchical structure based on the relationship between supertype and subtype abstract data types

[Figure]

(b) Substitutability

The values of a subtype can be treated as values of its supertype. This is called substitutability. Figure 13-27 shows the data structure of a table containing an abstract data type in which values are inserted using substitutability.

Figure 13-27 Data structure of a table containing an abstract data type (using substitutability)

[Figure]

(c) Override

A routine defined as a high-order abstract data type (supertype) can be overwritten with a low-order abstract data type (subtype) that has the same name. Defining a routine by overwriting in such a manner is called override. When override is used, the name of a routine called need not be changed depending on its type.

(3) Effects of using inheritance

When inheritance is used, the following effects can be expected:

(4) Defining an abstract data type

The CREATE TYPE definition SQL is used to define an abstract data type. CREATE TYPE defines the attributes indicating the structure of the abstract data type and defines the procedure for manipulating the values. If inheritance is used, the subtype clause of CREATE TYPE is specified. For an example of a CREATE TYPE definition, see 7.5 Creating a table containing a user-defined abstract data type.

(a) Defining a constructor function

A constructor function to be used to generate values for an abstract data type can be defined. The HiRDB system provides a default constructor function that can be used when an abstract data type is defined. The default constructor function generates values whose attributes are all the null value.

(b) Defining a routine

A routine can be defined in an abstract data type definition as an interface for manipulating the values of an attribute.

(c) Specifying an encapsulation level

An encapsulation level can be specified to control accesses to the attributes comprising an abstract data type and a routine. An encapsulation level can be specified for a routine that is used to manipulate attributes and the abstract data type's values. There are three encapsulation levels:

Once an encapsulation level is specified within the definition of an abstract data type, the encapsulation level remains in effect until another encapsulation level is specified. If no encapsulation level is specified, PUBLIC is assumed. The range of data access and routine usage privilege depends on the encapsulation level. Table 13-10 shows the encapsulation levels and privileges.

Table 13-10 Encapsulation levels and privileges

Encapsulation levelAccess source
Within the definition of the abstract data typeWithin the definition of its subtype abstract data typesWithin the definition of another abstract data type than those on the leftApplication
PUBLICPPPP
PRIVATEP[Figure][Figure][Figure]
PROTECTEDPP[Figure][Figure]
P: Accesses to attribute values and use of routines are permitted.
[Figure]: Accesses to attribute values and use of routines are not permitted (if violated, an SQL error results).