An OPM Tutorial

Contents

Classes and Class Hierarchy
Attributes
Inheritance
Instances
Types of Attributes
Derived Attributes
Derived Classes
Glossary of OPM Terms
Detailed Definition of OPM
Acknowledgement

Classes and Class Hierarchy

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.

Attributes

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.

Inheritance

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?

Instances

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.

Types of Attributes

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"

Derived Attributes

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.

Derived Class

Some classes may consist of objects (instances) that are determined by evaluating conditions associated with other classes. Such classes are called derived classes.
Example:
Red Apples can be defined as a derived class consisting of those (instances of class) Apples whose color is red. The instances of Red Apples are determined (computed) automatically when they are invoked, for example, in a query.

Glossary of OPM Terms

Attribute
A feature of an object or class. The attributes of a class essentially define the properties of that class. Examples.
Class
A collection of objects all of which have the same attributes.
Derived Attribute
An attribute that is computed from other attributes of the same or another class. Examples.
Derived Class
A class consisting of instances of other classes, satisfying a certain condition. Examples.
Inherited Attribute
A class is made up of its proper attributes and those of its superclasses. Those that are passed down from the superclasses are inherited attributes. Example
Instance
An occurrence of a particular class in the database. An instance of a class is defined by assigning specific values to each of the class's attributes. Examples.
Object
Same as Instance.
Proper Attribute
An attribute that is not inherited or computed from other attributes. One that is defined specifically for a given class.
Reference Attribute
An attribute that points to another object in the database.
Schema
What data you store and how you organize it depends on the purpose of your database. The specific organization of a database is called a schema.
Subclass
A more specific class of object that inherits its superclasses' attributes.
Superclass
A more general class of object that passes down its attributes to its subclasses.

Acknowledgement

This OPM tutorial has been adapted from a tutorial written by Sue Borchardt and Laurie Kramer, with assistance from Amy Voltz, Pat Foster, and Ken Fasman, of the Genome Database (GDB), Johns Hopkins School of Medicine in Baltimore. We are grateful for their permission to adapt their tutorial.