Contents
- Classes and Class Hierarchy
- Attributes
- Inheritance
- Instances
- Types of Attributes
- Derived Attributes
- Derived Classes
- Glossary of OPM Terms
- Detailed Definition of OPM
- Acknowledgement
It is natural to think of databases as storing objects representing
real-world entities such as person or city qualified by properties
(attributes) such as name.
A single database may contain information describing many types of real-world objects.
When the number of types of objects (referred to as classes) stored in a given database
begins to grow, it is useful to group them into related categories. It helps when categorizing
objects to place them in a hierarchy starting with the most general items at the top, working
down to more specific types as in a taxonomy. Objects in a hierarchy are often classified
according to shared propoerties called attributes.
The sample class hierarchy below is organized with the most general class of object as Fruit.
The objects in the Fruit class are divided into more specific kinds of Fruit such as
Melon, Oranges, and Apple. The Melon class is further divided
into Honeydew, Cantalope, and Watermelon.
Fruit
^
|
isa
|
+-------------+-------------+
| | |
isa isa isa
| | |
Melon Orange Apple
^
|
+-----+------+------------+
| | |
isa isa isa
| | |
Honeydew Cantaloupe Watermelon
In this example the classes Melon, Orange, and Apple are said to be
subclasses of the class Fruit. Honeydew is a subclass of both Melon and
Fruit. Fruit is said to be the superclass of Melon. The subclass relationship
can also be thought of as an isa relationship (short for "is a"). Honeydew isa
Melon and Honeydew isa Fruit.
The data chosen to describe the class are known as its attributes. The collection of
attributes for a given class depends on the purpose of the database. A grocer may wish to
store price per pound for a particular fruit. A farmer may wish to store a fruit's harvest date.
In the example used below, we will store information on the fruit grown on a given farm.
The attributes of the class Fruit are color and weight.
Color and weight are shared by all the subclasses of fruit. Apples have
color and weight; so do Cantaloupes and Watermelons. Color and weight are
called
inherited attributes because all subclasses inherit them.
In this example, Fruit has attributes color and weight.
Since Melon is also a Fruit, it will inherit the attributes color and weight.
Honeydew is also a Melon, and it too will inherit these attributes.
Color and weight are called inherited attributes of both Melon and
Honeydew.
A Class is said to inherit the attributes of its superclasses.
Thus each class has its own locally defined attributes (proper attributes),
as well as those attributes it has inherited from all of its superclasses in the class hierarchy.
The opposite of an inherited attribute is called a proper attribute. This is an
attribute which is not inherited. Color and weight are proper attributes of Fruit.
Melon also has its own attribute vine length. Vine length is called a proper attribute
of Melon. It is not inherited from Fruit, because not all fruits grow on vines.
In addition to the Honeydew's inherited attributes color and weight, it also inherits Melon's proper attribute
vine length. This is a proper attribute of Melon, but an inherited attribute of
Honeydew.
The following diagram shows the hierarchy already established, expanded to show the attributes of the classes.
Proper attributes are shown in UPPERCASE, Inherited attributes are shown in lowercase.
Fruit
- COLOR
- WEIGHT
|
|
|----------------------------------|
| | |
| | |
Melon Orange Apple
- color - color - color
- weight - weight - weight
- VINE LENGTH - SECTION COUNT - VARIETY
|
|
|------------|------------|
| | |
Honeydew Cantaloupe Watermelon
- color - color - color
- weight - weight - weight
- vine length - vine length - vine length
- HAS SEEDS?
A class defines what is stored in the database; an instance of the
class is the actual object that is stored. In fact, the terms instance
and object are often used interchangably, e.g., "The
objects returned as a result of a query...".
An instance of Watermelon might look like this:
- Watermelon
- color: green
- weight: 1.25
- vine length: 15
- has seeds?: true
The values supplied for the attributes describe a specific watermelon.
The problem here is that there might be many green watermelons, that came from a 15 foot vine
and weighed 1.25 pounds. To fully specify an instance there must be some way to uniquely
identify each watermelon to distinguish between those with identical characteristics.
Looking at the instance of Apple, and depending on the nature of the specific attribute, its value will be one of the following types:
- text
- color: "red"
- number
- weight (lbs): 10
- restricted value (the value must be selected from a set of predefined choices)
- variety: pick from list Rome, Winesap, Delicious
- list
- There can be one or more values for list attributes.
- Growing areas: Washington, Massachusetts, and California
- table (a set of related attributes)
- Tables are complex attributes with related sub-components.
- Orchard address:
- street: "Route 5"
- city: "Our Town"
- state: "MD"
- zip code:21205
- reference
- Reference attributes are those which point to another object in the database.
If we expand the example model to have a new class, Orchard, then
Apple can have the reference
attribute from orchard with which we can reference an instance of orchard.
- from orchard: "NorthEast Apple Orchard"
Some attributes values may be determined based on other attributes in that object or
another related object. These attributes are called derived attributes and are only of concern
to those wanting to insert or edit objects. Their values are not directly editable except by
changing the values from which they are derived.
- Example:
- Orchard has a derived attribute Apples. The value of
this attribute is a list of instances of the class Apple. This list is
determined automatically and is made up of all the Apples that "refer to"
this Orchard (via its reference attribute from orchard). Since the value
of Apples cannot be edited from the Orchard class the only way to change it
is to edit the from orchard attribute from the Apple class.