Subtypes Copyright © 1999 Patrick McDermott UC Berkeley Extension [email protected].
-
Upload
aubrey-johnston -
Category
Documents
-
view
217 -
download
1
Transcript of Subtypes Copyright © 1999 Patrick McDermott UC Berkeley Extension [email protected].
Inheritance CRC Cards: Superclass/Subclass ERD: Supertype/Subtype Relational: N/A Database: Three Variations Programmer: Base/Derived UML: Generalization/Specialization Etc., etc., etc.…: Is-a, Root/Branch/Leaf,
Extension
Types of Relationship
• IS-A: Generalization• HAS-A: Aggregation• IS-Made-From: Composition
– “A form of aggregation with strong ownership and coincident lifetime of parts by the whole.”– Rumbaugh, Reference, p. 226
– I don’t bother distinguishing from Aggregation
• USES: Association– Default; those that aren’t one of the others– Usually Name according to Use
Subtype
• A subtype is a subtype of another entity (supertype) where occurrences of both designate the same object in the real world, but the subtype has additional, more specific properties.
• The primary key of a subtype should be the same as the primary key of the supertype
Analogies• Base/Derived
– Generalization: General-Specific– Genus Species
• Supertype-Type-Subtype– Superclass-Subclass
• Tree– Root-Branch-Leaf
• Inheritance– Parent-Child [Cloned]
• “Is a”– “A Kind of”
Pietr Brueg(h)el (the Elder)The Tower of Babel, 1563
Teacher
TEACHER
NameAddressTelephoneSalary
GetPaid()GetHired()Quit()
PartTime
Hours
Contract()
Block Arrow:
Instead of Inheritance• Sometimes you DO want to inherit,
sometimes you don’t. or just some…
DelegationCompositionAggregation• Says can use to avoid violating LSP: BUT it
just avoids inheritance. In the end, they look the same in the database…
Super Type Confusion• More attributes means Fewer Objects• Supertype is subset of type...• If you understand the set theory from which
it comes, no (new) confusion
This has something more, else it would be in
the larger category
Employee
EMPLOYEE
NameAddressTelephoneGetHired()GetPaid()Transfer()Quit()
BlueCollar
HourlyRateUnionGetPaid()PayUnion()Grieve()
WhiteCollar
Salary
GetStock()
Block Arrow:
Should You Subclass?Different timesDifferent usersDifferent behavior
• If overlap a lot, don’t subclass
A Difference in Degree, or Kind?
c a’s fields
1 Record
2 Record Types
3 Records
a a’s fields
b b’s fields
b’s fieldscommon fields
common fields
common fields
c
a’s fields b’s fields
common fields
Used Only By as
Used Only By bs
Or
Type a Type b
Plain Type
K.I.S.S.• There must be a Business Need
– A Distinction without Difference– A difference is a difference only if it makes a
difference• Analogies aren’t exact• Too many levels can be confusing• Multiple Inheritance can be confusing• When in doubt, leave it out
– Anything that can be done with inheritance can be done without