lecture 03 handout

6
Lecture 3 CMPS 328 Generalization Rules Using Classes Diagramming and Denitions Attributes Rules Overlaps Benets Stopping Relationships 1 / 22 Subt ypes and Supert ypes CMPS 328 – Advanced Databases www.gheadley.org/ub/cmps328 University of Belize February 10, 2006 Lecture 3 CMPS 328 Generalization Rules Using Classes Diagramming and Denitions Attributes Rules Overlaps Benets Stopping Relationships 2 / 22 Outline 1 Dierent Levels of Generalization 2 Rules versus Stability 3 Using Subtypes and Supertypes 4 Subtypes and Supertypes as Entity Classes 5 Diagramming and Denitions 6 Attributes of Supertypes and Subtypes 7 Nonoverlapping and Exhaustive 8 Overlapping Subtypes and Roles 9 Benets of Subtypes Lecture 3 CMPS 328 Generalization Rules Using Classes Diagramming and Denitions Attributes Rules Overlaps Benets Stopping Relationships 3 / 22 Dierent Levels of Generalization Designing a database for family trees Data for mothers, fathers, marriages and children Simple problem statement that is quite hard Family tree designs Lecture 3 CMPS 328 Generalization Rules Using Classes Diagramming and Denitions Attributes Rules Overlaps Benets Stopping Relationships 4 / 22 Dierent Levels of Generalization Marriage class resolves many-to-many “be married to” Note optionality of “mother of” and “father of” While all have mothers, will run out of knowledge Choice of classes is the issue Nouns from problem, mother, father, child overlap Child, Mother have redundant data Examples take two approaches Person concept and man, woman concept

Upload: study4aim

Post on 29-May-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 03 Handout

8/8/2019 Lecture 03 Handout

http://slidepdf.com/reader/full/lecture-03-handout 1/6

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

1 / 22

Subtypes and Supertypes

CMPS 328 – Advanced Databases

www.gheadley.org/ub/cmps328

University of Belize

February 10, 2006

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

2 / 22

Outline

1 Different Levels of Generalization

2 Rules versus Stability

3 Using Subtypes and Supertypes

4 Subtypes and Supertypes as Entity Classes

5 Diagramming and Definitions

6 Attributes of Supertypes and Subtypes

7 Nonoverlapping and Exhaustive

8 Overlapping Subtypes and Roles

9 Benefits of Subtypes

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

3 / 22

Different Levels of Generalization

Designing a database for family trees

Data for mothers, fathers, marriages and children

Simple problem statement that is quite hard

Family tree designs

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

4 / 22

Different Levels of Generalization

Marriage class resolves many-to-many “be married to”

Note optionality of “mother of” and “father of”

While all have mothers, will run out of knowledge

Choice of classes is the issue

Nouns from problem, mother, father, child overlap

Child, Mother have redundant data

Examples take two approaches

Person concept and man, woman concept

Page 2: Lecture 03 Handout

8/8/2019 Lecture 03 Handout

http://slidepdf.com/reader/full/lecture-03-handout 2/6

Page 3: Lecture 03 Handout

8/8/2019 Lecture 03 Handout

http://slidepdf.com/reader/full/lecture-03-handout 3/6

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Naming

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

9 / 22

Subtypes and Supertypes as Entity Classes

Rule

Subtypes and supertypes are  entity classes.

Use the same diagram convention

Must be supported by definitionsCan have attributes – associate with relevant class

Can have relationships

Can be nested

Subtypes

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Naming

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

10 / 22

Subtypes and Supertypes as Entity ClassesNaming Subtypes

Remember subtypes are classes when naming

Use nouns not adjectives

Permanent Employee not Permanent

Domestic Customer not Domestic

Reasons

Documentation may show classes out of visual context

Automatic generation of tables will lose context

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

11 / 22

Diagramming and Definitions

Diagrams

Use box-in-box when you can

many tools don’t support subtypesShow as one-to-one – bad but beats nothing

Use relationship names to help – “be” or “is”

Careful to not confuse type association with relationships

Definitions

Rule – Entity class inherits the definition from supertype

Subtype definition is about differentiation

Job Position subtyped – Permanent and Temporary Job

Position

Definition for Permanent Job Position

“.. . a Job Position that .. . ”

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

12 / 22

Attributes of Supertypes and Subtypes

In our example

Attributes for all persons go inPerson

Attributes for only men or women go there

BirthDate goes in Person

Maiden Name goes in Woman

Subtyping at the attribute level

Class Contract – Renewable Contract, Fixed-TermContract

Hold Renewal Date with Renewable Contract

Hold Expiry Date with Fixed-Term Contract

Hold End Date with Contract

Page 4: Lecture 03 Handout

8/8/2019 Lecture 03 Handout

http://slidepdf.com/reader/full/lecture-03-handout 4/6

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

13 / 22

Nonoverlapping and Exhaustive

Rule – Subtypes

1 They are nonoverlapping – cannot be both

2 They are exhaustive – must be either

Person cannot be both a man and a woman

Person must be either a man or a woman

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Benefits

Stopping

Relationships

14 / 22

Nonoverlapping and Exhaustive

Trading Partner model subtyped into Buyer and Seller

If Buyer can also be Seller then overlap

Discard supertype, implement subtypes – redundant dataAgent is neither Buyer nor Seller

Discard supertype, implement subtypes – lose data

Detailed look at family tree model

Sure we can classify into man or woman?

Do we know sex? Records can be incomplete

How do we handle unknown?

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Ignore

Supertype Only

Participation

Role Classes

Benefits

Stopping

Relationships

15 / 22

Overlapping Subtypes and Roles

We said no overlaps in subtypesBusinesses deal with people and organizations

Many roles: supplier, customer, investor, account holder,

employee

How can we subtype without overlap ?

Good news – people and organizations only common

major issue

Several tactics

Lecture 3

CMPS 328

Generalization

Rules

Using

Classes

Diagramming andDefinitions

Attributes

Rules

Overlaps

Ignore

Supertype Only

Participation

Role Classes

Benefits

Stopping

Relationships

16 / 22

Overlapping Subtypes and RolesIgnore Real-World Overlaps

Sometimes we can model as-if overlaps don’t exist

Same person as separate customer and supplier

What business value of knowing they are the same

person

Discretion again !!!

Do this with care !

Bank have one class for borrowers, guarantors,

depositors

Other classes for suppliers and stockholders

Page 5: Lecture 03 Handout

8/8/2019 Lecture 03 Handout

http://slidepdf.com/reader/full/lecture-03-handout 5/6

Page 6: Lecture 03 Handout

8/8/2019 Lecture 03 Handout

http://slidepdf.com/reader/full/lecture-03-handout 6/6