You are on page 1of 6

Outline

Lecture 3 Lecture 3
1 Different Levels of Generalization
CMPS 328 CMPS 328

Generalization 2 Rules versus Stability Generalization

Rules Rules
Subtypes and Supertypes Using 3 Using Subtypes and Supertypes Using

Classes Classes

Diagramming and 4 Subtypes and Supertypes as Entity Classes Diagramming and


CMPS 328 – Advanced Databases Definitions Definitions

Attributes Attributes
www.gheadley.org/ub/cmps328 5 Diagramming and Definitions
Rules Rules

University of Belize Overlaps Overlaps


6 Attributes of Supertypes and Subtypes
Benefits Benefits

February 10, 2006 Stopping


7 Nonoverlapping and Exhaustive
Stopping

Relationships Relationships

8 Overlapping Subtypes and Roles

1 / 22 9 Benefits of Subtypes 2 / 22

10 When To Stop Supertyping and Subtyping

Different Levels of Generalization Different Levels


11 Generalization of Generalization
of Relationships

Lecture 3 Lecture 3

CMPS 328 CMPS 328


Designing a database for family trees
Generalization Generalization
Data for mothers, fathers, marriages and children Marriage class resolves many-to-many “be married to”
Rules Rules
Simple problem statement that is quite hard Using Note optionality of “mother of” and “father of” Using

Classes While all have mothers, will run out of knowledge Classes
Family tree designs Diagramming and Diagramming and
Definitions Choice of classes is the issue Definitions

Attributes
Nouns from problem, mother, father, child overlap Attributes

Rules Rules
Child, Mother have redundant data
Overlaps Overlaps

Benefits Examples take two approaches Benefits

Stopping Person concept and man, woman concept Stopping

Relationships Relationships

3 / 22 4 / 22
Different Levels of Generalization Rules versus Stability

Lecture 3 Lecture 3

CMPS 328
Important difference between models - number of rules CMPS 328
man-woman – three classes, six relationships
Difference is on level of generalization Generalization
person – two classes, four relationships Generalization

Rules Rules
Person is generalization of Man, Woman man-woman seems to represent more rules
Using Using
Man, Woman are specializations of Person Classes
man-woman – marriage is one man and one woman Classes

Other choices – Marriage to Personal Relationship Diagramming and


person – marriage allows same sex Diagramming and
Definitions person – two parents of same sex Definitions
Choice of level profound effect on database and system Attributes
man-woman – mother, woman and man, father Attributes

Generalization – reduces classes, simplifies model Rules


Rules can be enforced elsewhere Rules

Overlaps Overlaps
Only sometimes reduce system complexity person – sex rules in program logic
Benefits Benefits
Often causes complexity by combining logic for subtypes Choice is where to build rules into system
Stopping Stopping

Reducing classes versus programming complexity Changing running database structure is expensive
Relationships Relationships
Assess likelihood of rule change in system lifetime
Likely – program logic
Not – database model
5 / 22 6 / 22

Rules versus Stability Using Subtypes and Supertypes

Lecture 3 Lecture 3

Guideline CMPS 328 So we decide to go with person model CMPS 328

Do not build a rule into the data structure of a system unless Nice not to lose rules specific to men and woman
Generalization Generalization
you are reasonably confident that the rule will remain in force Even without subtypes, document the rules
Rules Rules

for the life of the system. Using


Defer the decision on generalization Using

Classes
Problem of right level, opportunity to explore options Classes

Guideline Diagramming and


Allow several models to exist on top of one another Diagramming and
Definitions Definitions
Use generalization to remove unwanted rules from the data Attributes Attributes
Family tree designs
model. Rules Rules

Overlaps Overlaps

Novice models often have too many rules Benefits Benefits

Stopping Stopping
Tendency to over do generalization
Relationships Relationships
Rules must exist somewhere – right place
Very general models abdicate responsibility
7 / 22 8 / 22
Subtypes and Supertypes as Entity Classes Subtypes and Supertypes as Entity Classes
Naming Subtypes

Lecture 3 Lecture 3
Rule
CMPS 328 CMPS 328
Subtypes and supertypes are entity classes.
Generalization Generalization

Use the same diagram convention Rules


Remember subtypes are classes when naming Rules

Must be supported by definitions Using


Use nouns not adjectives
Using

Classes Classes
Can have attributes – associate with relevant class Naming Naming
Can have relationships Permanent Employee not Permanent
Diagramming and Diagramming and

Can be nested Definitions Domestic Customer not Domestic Definitions

Attributes Attributes
Reasons
Subtypes Rules Rules
Documentation may show classes out of visual context
Overlaps Overlaps
Automatic generation of tables will lose context
Benefits Benefits

Stopping Stopping

Relationships Relationships

9 / 22 10 / 22

Diagramming and Definitions Attributes of Supertypes and Subtypes

Lecture 3 Lecture 3

Diagrams CMPS 328 CMPS 328

Use box-in-box when you can Generalization


In our example Generalization

many tools don’t support subtypes Rules


Attributes for all persons go in Person Rules
Attributes for only men or women go there
Show as one-to-one – bad but beats nothing Using Using
BirthDate goes in Person
Use relationship names to help – “be” or “is” Classes
Maiden Name goes in Woman
Classes

Diagramming and Diagramming and


Careful to not confuse type association with relationships Definitions Definitions
Subtyping at the attribute level
Definitions Attributes Attributes

Rules Rules
Rule – Entity class inherits the definition from supertype Class Contract – Renewable Contract, Fixed-Term
Overlaps Overlaps
Subtype definition is about differentiation Contract
Benefits Benefits
Job Position subtyped – Permanent and Temporary Job Hold Renewal Date with Renewable Contract
Stopping Stopping
Position Hold Expiry Date with Fixed-Term Contract
Relationships Relationships
Definition for Permanent Job Position Hold End Date with Contract
“. . . a Job Position that . . . ”
11 / 22 12 / 22
Nonoverlapping and Exhaustive Nonoverlapping and Exhaustive

Lecture 3 Lecture 3

CMPS 328 CMPS 328


Trading Partner model subtyped into Buyer and Seller
Generalization Generalization

Rules If Buyer can also be Seller then overlap Rules


Rule – Subtypes Using Discard supertype, implement subtypes – redundant data Using
1 They are nonoverlapping – cannot be both Classes
Agent is neither Buyer nor Seller Classes

Diagramming and Diagramming and


2 They are exhaustive – must be either Definitions Discard supertype, implement subtypes – lose data Definitions

Attributes Attributes
Detailed look at family tree model
Person cannot be both a man and a woman Rules Rules

Overlaps Overlaps
Person must be either a man or a woman Sure we can classify into man or woman?
Benefits Benefits

Stopping Do we know sex? Records can be incomplete Stopping

Relationships How do we handle unknown? Relationships

13 / 22 14 / 22

Overlapping Subtypes and Roles Overlapping Subtypes and Roles


Ignore Real-World Overlaps

Lecture 3 Lecture 3

CMPS 328 CMPS 328

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


We said no overlaps in subtypes Rules Rules
Same person as separate customer and supplier
Businesses deal with people and organizations Using Using

Classes What business value of knowing they are the same Classes
Many roles: supplier, customer, investor, account holder,
Diagramming and person Diagramming and
employee Definitions Definitions

Attributes
Discretion again !!! Attributes
How can we subtype without overlap ?
Rules Do this with care ! Rules
Good news – people and organizations only common Overlaps Overlaps
major issue Ignore
Bank have one class for borrowers, guarantors, Ignore
Supertype Only
depositors Supertype Only

Several tactics Participation


Role Classes
Participation
Role Classes

Benefits
Other classes for suppliers and stockholders Benefits

Stopping Stopping

Relationships Relationships

15 / 22 16 / 22
Overlapping Subtypes and Roles Overlapping Subtypes and Roles
Modeling only the Supertype Modeling the Roles as Participation in Relationships

Lecture 3 Lecture 3

CMPS 328 CMPS 328

Generalization Generalization
Use one supertype for all roles Rules Rules

Subtyping done on other criterion Using


Describe Customer as Party who has an Account Using

Such as “legal entity class type” – company, partnership Classes Describe Supplier as Party who has a Contract Classes

Lose that some relationships apply only to some roles


Diagramming and
Definitions
How to diagram Party-Account and Party-Contract Diagramming and
Definitions

Can be documented Attributes Normal relational arrows can’t hack it Attributes

Rules Rules
“Market Segment must be recorded if this Party has the Chen notation
Overlaps Overlaps
Role of Customer” Ignore Document in description of Party Ignore
Supertype Only Supertype Only
Participation Participation
Lost from diagram Role Classes Role Classes

Benefits Benefits

Stopping Stopping

Relationships Relationships

17 / 22 18 / 22

Overlapping Subtypes and Roles Benefits of Subtypes


Using Role Entity Class and One-to-one Relationships

Lecture 3 Lecture 3
Many options on one diagram, each level is an option
Role entity classes CMPS 328 As we propose classes CMPS 328

Generalization Can this be subtyped for more distinct concepts Generalization

Rules
Can we generalize these into a supertype Rules

Using
Simplify the “big picture” for communication Using

Classes
Summarize by removing subtypes Classes

Diagramming and
Vary across the model according to interest, audience Diagramming and
Create an class to hold the role Definitions Inviable models can be useful with customers Definitions

One-to-one relation between party and role Attributes Must finish viable first Attributes

Role entity class supertyped into Party Role Rules Allows synonyms Rules

Normal not implemented – lose too much information Overlaps Truck as an Asset subtype Overlaps
Ignore
Motor Pool Manager versus Accountant Benefits
Sometimes some intermediate supertyping Supertype Only
Participation Financial Instrument into Bond and Bill Stopping
All buyers of insurance same – type irrelevant Role Classes
Never have to implement
Benefits Relationships
“Role” is always in the class name – no primary data Inform view designs, capture rules
Stopping
Usually the neatest solution Develop design patterns
Relationships

19 / 22 Multiple modelers 20 / 22
When To Stop Supertyping and Subtyping Generalization of Relationships

Lecture 3 Lecture 3

CMPS 328 As we generalize and specialize entity classes CMPS 328


Supertyping is easy – one supertype Relationships also generalize and specialize too
Generalization Generalization
Supertyping to single figures is common Rules Several one-to-many can become a many-to-many Rules

Can subtype every optional attribute Using


Several one-to-many can become one many-to-many –
Using

Classes Classes
In practice more nuanced exclusivity
Diagramming and Diagramming and
When in doubt subtype Definitions Definitions

Differences in identifying attributes Attributes Mutual Exclusive Relationships Attributes

Equipment into Vehicle and Machine – different Rules Rules

numbering Overlaps Overlaps

Difference in attributes Benefits Benefits


House Policy versus Vehicle Policy Stopping Stopping
Different, not optional, relationships or processes Relationships Relationships
Vehicle has a Driver, Machine does not

21 / 22 22 / 22

You might also like