Académique Documents
Professionnel Documents
Culture Documents
Magda Balazinska - CSE 344, Fall 2011 1 Magda Balazinska - CSE 344, Fall 2011 2
1
name category
name
Entity / Relationship Diagrams
This is an price
entity set
Objects entities makes Company
Product Product
Classes entity sets
stockprice
Attributes are like in ODL address
(ODL = Object Definition Language)
buys
employs
Relationships: like in ODL except buys
Person
- first class citizens (not associated with classes)
- not necessarily binary
name category
name
Multiplicity of E/R Relations
price
• one-one: makes Company
1 a
2 b Product
3 c
• many-one d
stockprice
1 a
What does
2 b this say ?
3 c buys
d employs
• many-many
1 a
Person
2 b
3 c
d
2
Multi-way Relationships Arrows in Multiway Relationships
How do we model a purchase relationship between buyers,
Q: What does the arrow mean ?
products and stores?
Product Product
Purchase Store
Purchase Store
Person
Person
A: A given person buys a given product from at most one store
Can still model as a mathematical set (how ?) 13 Magda Balazinska - CSE 344, Fall 2011 14
Product Product
Person Person
A: A given person buys a given product from at most one store A: Cannot. This is the best approximation.
AND every store sells to every person at most one product (Why only approximation ?)
Magda Balazinska - CSE 344, Fall 2011 15 Magda Balazinska - CSE 344, Fall 2011 16
Purchase
StoreOf Store
Country President Person
3
Design Principles: Design Principles:
What’s Wrong? What’s Wrong?
date
Dates date
Product
Product
Purchase Store
Purchase Store
Moral: pick the right
kind of entities. Moral: don’t
personAddr complicate life more
personName than it already is.
Magda Balazinska - CSE 344, Fall 2011 19 Person 20
4
Multi-way Relationships to
Modeling Subclasses
Relations
name address
Product
Some objects in a class may be special
• define a new class
Purchase Store • better: define a subclass
name price
Products
Purchase(prodName,stName,ssn)
Software Educational
Person products products
Subclasses
name category Understanding Subclasses
price
• Think in terms of records: field1
– Product field2
Product
– SoftwareProduct field1
field2
isa isa – EducationalProduct field3
field1
Software Product Educational Product field2
field4
field5
Magda Balazinska - CSE 344, Fall 2011 Magda Balazinska - CSE 344, Fall 2011 28
platforms Age Group
Subclasses to Product
Relations Name Price Category
Modeling UnionTypes With
name category Gizmo 99 gadget Subclasses
Camera 49 photo
price
Toy 39 gadget FurniturePiece
Product
5
Modeling Union Types with Modeling Union Types with
Subclasses Subclasses
Say: each piece of furniture is owned either by a Solution 2: better, more laborious
person or by a company Owner
Solution 1. Acceptable but imperfect (What’s wrong ?)
Person FurniturePiece Company isa isa
ownedBy
Person Company
ownedByPerson ownedByComp.
FurniturePiece
Magda Balazinska - CSE 344, Fall 2011 31 Magda Balazinska - CSE 344, Fall 2011 32