11.1 Overview of Object Database Concepts 365
A type is defined by assigning it a type name, and then defining a number of attrib-
utes (instance variables) and operations (methods) for the type.
16
In the simplified
model we use in this section, the attributes and operations are together called
functions, since attributes resemble functions with zero arguments. A function
name can be used to refer to the value of an attribute or to refer to the resulting
value of an operation (method). We use the term function to refer to both attrib-
utes and operations, since they are treated similarly in a basic introduction to inher-
itance.
17
A type in its simplest form has a type name and a list of visible (public) functions.
When specifying a type in this section, we use the following format, which does not
specify arguments of functions, to simplify the discussion:
TYPE_NAME: function, function, ..., function
For example, a type that describes characteristics of a PERSON may be defined as
follows:
PERSON: Name, Address, Birth_date, Age, Ssn
In the PERSON type, the Name, Address, Ssn, and Birth_date functions can be imple-
mented as stored attributes, whereas the
Age function can be implemented as an
operation that calculates the
Age from the value of the Birth_date attribute and the
current date.
The concept of subtype is useful when the designer or user must create a new type
that is similar but not identical to an already defined type. The subtype then inher-
its all the functions of the predefined type, which is referred to as the supertype.For
example, suppose that we want to define two new types
EMPLOYEE and STUDENT
as follows:
EMPLOYEE: Name, Address, Birth_date, Age, Ssn, Salary, Hire_date, Seniority
STUDENT: Name
, Address, Birth_date, Age, Ssn, Major, Gpa
Since both STUDENT and EMPLOYEE include all the functions defined for PERSON
plus some additional functions of their own, we can declare them to be subtypes of
PERSON. Each will inherit the previously defined functions of PERSON—namely,
Name, Address, Birth_date, Age, and Ssn.For STUDENT, it is only necessary to define
the new (local) functions
Major and Gpa, which are not inherited. Presumably, Major
can be defined as a stored attribute, whereas Gpa may be implemented as an opera-
tion that calculates the student’s grade point average by accessing the
Grade values
that are internally stored (hidden) within each
STUDENT object as hidden attributes.
For
EMPLOYEE, the Salary and Hire_date functions may be stored attributes, whereas
Seniority may be an operation that calculates Seniority from the value of Hire_date.
16
In this section we will use the terms type and class as meaning the same thing—namely, the attributes
and operations of some type of object.
17
We will see in Section 11.3 that types with functions are similar to the concept of interfaces as used in
ODMG ODL.