munotes®

Practical 1: Generalization and Specialization

Chapter Thirty-One

Syllabus topic Module 2, Practical 1: "... generalization, specialization etc."

Pages 112 to 114 of 206

Aim

To apply generalization and specialization to an ER design.

The problem both of them solve

Suppose the library has two kinds of member: students, who have a course, and staff, who have a department. Both kinds have a member id, a name and a date of joining.

Two entity sets, and most of their attributes are the same:

STUDENTSTAFF
member_idmember_id
namename
joined_onjoined_on
coursedepartment

That repetition is the smell. If a third kind of member appears later, the shared attributes are written a third time, and a change to one of them has to be made in three places.

Generalization: bottom up

Generalization takes two or more entity sets that share attributes and pulls the shared ones up into a new, more general entity set.

STUDENT and STAFF become subclasses of a new MEMBER, which holds member_id, name and joined_on. STUDENT keeps only course; STAFF keeps only department.

Generalization: MEMBER with STUDENT and STAFF beneath it

Figure 31.1 The superclass holds what they share; each subclass adds only what is its own

The triangle marked ISA is the notation, and it is read "is a": a student is a member. The superclass is above it, the subclasses below.

Generalization is bottom up. You start with the specific sets, notice what they share, and invent the general one.

Specialization: top down

Specialization is the same picture arrived at from the other end. You start with MEMBER, notice that some members have a course and others have a department, and split the set into subclasses.

GeneralizationSpecialization
Directionbottom uptop down
You start withseveral specific entity setsone general entity set
You are looking forwhat they have in commonhow they differ
Resulta new superclassnew subclasses
Drawn asthe same ISA trianglethe same ISA triangle

The picture is identical; only the thinking that produced it differs. That is the whole distinction, and it is exactly what a viva asks. Do not look for a difference in the diagram, because there is none.

Attribute inheritance

A subclass inherits every attribute of its superclass, and every relationship the superclass takes part in.

So STUDENT has member_id, name, joined_on and course, even though only course is drawn beside it. And if MEMBER borrows books, a student borrows books without the relationship being drawn again.

That is what makes the arrangement worth having: say a thing once, and everything below inherits it.

The two constraints, which are asked by name

Disjoint or overlapping. May one entity belong to more than one subclass at the same time?

  • Disjoint, sometimes marked d: no. A member is a student or a member of staff, not both.
  • Overlapping, marked o: yes. A person might be both a student and a member of staff, at a college that employs its own research students.
munotes.in112

Practical 1: Generalization and Specialization

Total or partial. Must every entity of the superclass belong to some subclass?

  • Total: yes, drawn with a double line into the triangle. Every member is either a student or staff, and there is no third kind.
  • Partial: no, a single line. There may be members who are neither, such as an alumnus.

The two constraints are independent, so there are four combinations, and a complete answer names one from each pair: "disjoint and total", "overlapping and partial", and so on.

Aggregation, the other thing the triangle is confused with

Aggregation treats a whole relationship as though it were an entity set, so that another relationship can be attached to it. It is drawn as a box round the diamond and the two rectangles it joins.

The library's example: a member borrows a book, and the library wants to record which member of staff approved a particular borrowing. approved_by connects a member of staff to the borrowing, not to the member and not to the book separately, so the borrows relationship is boxed and the new diamond is attached to the box.

It is not generalization and it is not a weak entity set. Examiners ask students to tell the three apart, and the answer is:

What it isDrawn as
Generalizationa subclass is a kind of superclassISA triangle
Weak entity setan entity that cannot be identified alonedouble rectangle, double diamond
Aggregationa relationship treated as an entity seta box round a relationship

Where this goes next

A superclass and its subclasses can be turned into tables in three ways, and choosing between them is part of [Practical 8: Turning the ER Model Into Tables]:

One table per entity set. MEMBER, STUDENT and STAFF, with the subclass tables holding the key and their own attributes only. This is the general answer and works for every combination of constraints.

One table per subclass only. STUDENT and STAFF each hold all the inherited attributes as well. This works only when the specialization is total and disjoint; otherwise an entity belonging to no subclass has nowhere to live.

One table for everything. A single MEMBER table with course and department both in it, and one of them null for each row, plus a column saying which kind it is. Simple, and it fills the table with nulls.

What beginners get wrong

Looking for a difference between the two diagrams. There is none. The difference is in how you got there.

Repeating the inherited attributes beside the subclasses. They are inherited; drawing them again is a mistake, not extra detail.

munotes.in113

Practical 1: Generalization and Specialization

Confusing disjoint with total. Disjoint is about belonging to two subclasses at once; total is about belonging to none.

Using an ISA triangle for a relationship. A student is a member; a member borrows a book. The first is ISA, the second is a diamond. "Is a" against "does something to" is the test.

Specialising on a value that changes every day. If the subclass a row belongs to changes often, a column holding the kind is simpler than two tables.

Quick revision

  • Generalization is bottom up: pull shared attributes into a new superclass.
  • Specialization is top down: split a superclass into subclasses.
  • The diagram is the same for both: an ISA triangle.
  • Subclasses inherit every attribute and every relationship of the superclass.
  • Disjoint means an entity is in at most one subclass; overlapping means it may be in several.
  • Total means every superclass entity is in some subclass; partial means it need not be.
  • Aggregation boxes a relationship so another relationship can attach to it.
  • Three ways to make tables from it: one per entity set, one per subclass, or one for everything.

What goes in your journal

Aim, the two subclasses with the attributes they share listed separately from the attributes that are their own, the diagram with the ISA triangle, and a line naming both constraints, such as "disjoint and total". In the conclusion write the one sentence distinguishing generalization from specialization, because that sentence is the viva question for this half of the practical.

Test yourself

1. What is the difference between generalization and specialization? The direction of thinking. Generalization starts with specific entity sets and pulls out what they share into a new superclass. Specialization starts with one general entity set and divides it. The resulting diagram is the same.

2. What does the ISA triangle mean? That each subclass is a kind of the superclass: a student is a member.

3. What does a subclass inherit? Every attribute of its superclass and every relationship the superclass takes part in.

4. What is the difference between a disjoint and an overlapping specialization? Disjoint means an entity may belong to at most one subclass. Overlapping means it may belong to more than one at the same time.

5. What does total specialization mean? That every entity of the superclass must belong to at least one subclass. It is drawn with a double line into the triangle.

6. How is aggregation different from generalization? Aggregation treats a whole relationship as an entity set so that another relationship can be joined to it, and is drawn as a box. Generalization arranges entity sets into a kind-of hierarchy with a triangle.

munotes.in114

The rest of this subject

These notes are cut from the University's printed syllabus. Open the syllabus itself for the same subject.

Report or request
Done!