Broad Network


Generalization Association

Database Essentials - Part 9

Division 1

Forward: In this part of the series, we look at what is called the Generalization Association. This is another kind of relationship we have to learn.

By: Chrysanthus Date Published: 4 Aug 2012

Introduction

This is part 9 of my series, Database Essentials. Database Essentials is division 1 of a set of tutorials I have on Database. In this part of the series, we look at what is called the Generalization Association. This is another kind of relationship we have to learn. Our aim is to discover the nature of this association and not to know how to derive it or when to use it or how to use it.

Meaning of Generalization Relationship
In a Generalization association, you have a set of classes (tables) in a hierarchy, looking like a directory tree when the class diagram is drawn. The class at the top is the base class. Each class below another inherits the properties (columns) of its parent class. So all the sub classes inherit the properties of the base class.

Illustration
You will have to open the following link in a browser tab to see the tables and diagrams of this tutorial (link below).

Imagine that you own a pet store where you are selling pets (animals). Table 9.1 shows a sample table of the animals you have and the properties (characteristics) of the animals. These properties are the columns of the table. You have the AnimalID column, the DateBorn column, the column for the name of the animal, the Gender column, the column for the color of the animal, the column for the size of the litter, the column for whether or not the animal has claws, the column to indicate whether the animal is of fresh water and a column to indicate the type of scales of the animal.

There is a problem with the table. A pet customer comes to your store already knowing the type of animal she wants to buy. She may want to buy a cat, which is a mammal or a fresh water fish or some other animal specie. A customer who wants to buy a mammal would be interested in the litter size of the pet and whether or not the pet has claws; she would not be interested in the properties of the fishes. On the other hand a fish customer would want to know if the fish she is to buy is fresh-water fish or salt-water fish; she would not be interested in the properties of the mammals.

http://www.broad-network.com/ChrysanthusForcha/Generalization-Relationships.htm

Look at table 9.1 again and note that there are some generic properties for all the animals and there are other properties that are not relevant to all animals. The DateBorn, Name, Gender and Color properties are common (generic) to all animals. However the LitterSize and Claws properties are relevant only to mammals and not to fishes or some other category. The FreshWater and ScaleCondition properties are relevant only to fishes and not to other categories of animals. The number of properties for this table can be many; I have just mentioned a few.
Because not all properties are relevant to all animals, some of the table cells are empty. These empty table cells are said to have null values. Table 9.1 is not a very convenient table.  This table actually has three groups: the generic main group (columns), the mammal sub group (columns) and the fishes sub group (columns). So it is nice to have three tables instead of one large table. The main table for the generic properties becomes the base table. Then you would have the mammal and fishes sub tables. Table 9.2 is the main generic table with name, Animal. Table 9.3 is the mammal sub table with name Mammal. Table 9.4 is the fishes sub table with name Fishes.

Inheritance
In order to link the sub tables to the main table, the sub tables have the ID (primary key) column. Each ID in a sub table is found in the main table. In the case of the pet store the ID is the AnimalID. With this, in the implementation, the DBMS will know that the sub tables inherit the generic properties of the main table. For example, each mammal has a DateBorn and Name. These generic properties are not in the sub tables.

Class Diagram
Fig 9.1 shows the class diagram for the above tables. A small, unfilled triangle is used to indicate the generalization association. Lines form the sub classes are connected to the triangle. In the diagram the base class (table) is at the top and the sub classes (or inherited) classes are below. The sub classes inherit the properties and methods (see later) of the base class. The inherited properties are not repeatedly typed in the sub class diagrams.

The tree can continue downward. The mammal class (category) can be further split into cat and dog classes (categories), making the tree to grow downward. In the mammal class, there would be generic properties, which would be common to cat and dog classes. You do not only need to have two sub classes per parent class, you can have three, four, five, or any number.

Note: It is possible for a sub class to have two parents; that is not considered in this tutorial.

Conclusion
In a Generalization relationship, you have a set of classes in a hierarchy. The class at the top is the base class. Each class below another inherits the properties (columns) of its parent class. All the sub classes inherit the properties of the base class.

Let us stop here and continue in the next part of the series.

Chrys

Related Links

Major in Website Design
Web Development Course
HTML Course
CSS Course
ECMAScript Course
NEXT

Comments

Become the Writer's Fan
Send the Writer a Message