More Design Issues 1. Roles. 2. Sub classes. 3. Keys. 4. W - - PDF document

more design issues 1 roles 2 sub classes 3 keys 4 w eak
SMART_READER_LITE
LIVE PREVIEW

More Design Issues 1. Roles. 2. Sub classes. 3. Keys. 4. W - - PDF document

More Design Issues 1. Roles. 2. Sub classes. 3. Keys. 4. W eak en tit y sets. 5. Design principles and some hard examples. 1 Roles Sometimes an E.S. participates more than once in a relationship. Lab el edges


slide-1
SLIDE 1 More Design Issues 1. Roles. 2. Sub classes. 3. Keys. 4. W eak en tit y sets. 5. Design principles and some hard examples. 1
slide-2
SLIDE 2 Roles Sometimes an E.S. participates more than
  • nce
in a relationship.
  • Lab
el edges with r
  • les
to distinguish. Married Drink ers wife h usband Husband Wife d 1 d 2 d 3 d 4
  • 2
slide-3
SLIDE 3 Drink ers 1 2 Buddies Buddy1 Buddy2 d 1 d 2 d 1 d 3 d 2 d 1 d 2 d 4
  • Notice
Buddies is symmetric, Marrie d not.

No w a y to sa y \symmetric" in E/R.

But in ODL, symmetric relations are their
  • wn
in v erse. 3
slide-4
SLIDE 4 Roles in ODL No problem; names
  • f
relationships handle \roles." interface Drinkers { attribute string name; attribute Struct Bars::Addr address; relationship Set<Beers> likes inverse Beers::fans; relationship Set<Bars> frequents inverse Bars::customers; relationship Drinkers husband inverse wife; relationship Drinkers wife inverse husband; relationship Set<Drinkers> buddies inverse buddies; }
  • Notice
that Drinkers:: is
  • ptional
when the in v erse is a relationship
  • f
the same class. Design Issue Should w e replace husband and wife b y
  • ne
relationship spouse? 4
slide-5
SLIDE 5 Sub classes Sub class = sp ecial case = few er en tities/ob jects = more prop erties.
  • Example:
Ales are a kind
  • f
b eer. In addition to the prop erties (= attributes, relationships, metho ds)
  • f
b eers, there is a \color" attribute for ales. ODL Sub classes F
  • llo
w name
  • f
sub class b y colon and its sup erclass. interface Ales:Beers { attribute String color; }
  • Ob
jects
  • f
the Ales class acquire all the attributes and relationships
  • f
the Beers class. 5
slide-6
SLIDE 6 E/R Sub classes
  • isa
triangles indicate the sub class relation. isa Beers Ales name manf color 6
slide-7
SLIDE 7 Dierence in Sub class Viewp
  • in
ts
  • In
ODL, an en tit y is in exactly
  • ne
class.

It inherits prop erties
  • f
its sup erclass(es).
  • In
E/R, an en tit y has \represen tation" in all the sub classes to whic h it logicall y b elongs.

Its prop erties are the union
  • f
the prop erties
  • f
these classes.
  • The
distincti
  • n
matters later, when w e con v ert ODL and E/R to relations. isa Beers Ales name manf color P ete's Ale 7
slide-8
SLIDE 8 Multiple Inheritance Theoreticall y , a class/E.S. could b e a sub class
  • f
sev eral classes. isa isa name manf name manf Beers Wines Grap e Beers 8
slide-9
SLIDE 9 Problems Ho w should conicts b e resolv ed?
  • Example:
manf means gro w er for wines, b
  • ttler
for b eers. What do es manf mean for \grap e b eers"?
  • E/R
m ute
  • n
m ultiple inheritance; ODL lea v es it to implemen ter. 9
slide-10
SLIDE 10 Keys = set
  • f
attributes whose v alues can b elong to at most
  • ne
en tit y
  • r
  • b
ject.
  • In
E/R: underline all k ey attributes.
  • In
E/R, eac h E.S. m ust ha v e a k ey .
  • Example:
Supp
  • se
name is k ey for Be ers. isa Beers Ales manf color name
  • Beer
name is also k ey for ales.

In general, k ey at ro
  • t
(no m ultiple inheritance!) is k ey for all. 10
slide-11
SLIDE 11 Keys in ODL Indicate with key(s) follo wing the class name, and a list
  • f
attributes forming the k ey .

Sev eral lists ma y b e used to indicate sev eral alternativ e k eys.

P aren theses group mem b ers
  • f
a k ey , and also group key to the declared k eys.

Th us, (key(a 1 ; a 2 ; : : : ; a n )) = \one k ey consisting
  • f
all n attributes." (key a 1 ; a 2 ; : : : ; a n ) = \eac h a i is a k ey b y itself.
  • Example:
interface Beers (key name) { attribute string name ... 11
slide-12
SLIDE 12 A Multiattribute Key Courses dept n um b er hours ro
  • m
interface Courses (key (dept, number), (room, hours)) { ...
  • E/R
requires exactly
  • ne
k ey , but ODL allo ws zero
  • r
more k eys.
  • V
ery Imp
  • rtan
t: In ODL, \ob ject iden tit y" serv es to distinguish
  • b
jects, so no key at al l is ne c essary. 12
slide-13
SLIDE 13 W eak En tit y Sets Sometimes an E.S.'s k ey comes not (completely) from its
  • wn
attributes, but from the k eys
  • f
  • ne
  • r
more E.S's to whic h the rst is link ed b y a man y-one relationship.
  • Called
a we ak E.S.
  • Represen
ted b y putting double rectangle around the w eak E.S. and a double diamond around eac h relationship to whic h the w eak E.S. is link ed to an E.S. that pro vides part
  • f
its k ey .
  • Use
  • f
man y-one relationship (includes 1-1) essen tial.

With a man y-man y , w e w
  • uldn't
kno w whic h en tit y pro vided the k ey v alue.
  • V
ery Imp
  • rtan
t: There is no suc h thing as a \w eak class" in ODL.

Because
  • b
jects ha v e
  • b
ject-iden tit y , classes don't need k eys, and therefore they don't need to \b
  • rro
w" k eys from related classes. 13
slide-14
SLIDE 14 Example: Logins Login name = user name + host name, e.g., ullman@shalmaneser .stan ford. edu.
  • A
\login" en tit y corresp
  • nds
to a user name
  • n
a particular host, but the passwd table do esn't record the host, just the user name, e.g. ullman.
  • Key
for a login = the user name at the host (whic h is unique for that host
  • nly)
+ the name
  • f
the host (whic h is unique globally) . @ Logins Hosts name name 14
slide-15
SLIDE 15 Example: Chain
  • f
\W eakness" Consider IP addresses consisting
  • f
a primary domain (e.g., edu) sub domain (e.g., stanford), and host (e.g. shalmaneser). name name name Primary Domains In1 In2 Hosts Domains 2ndary
  • Key
for primary domain = its name.
  • Key
for secondary domain = its name + name
  • f
primary domain.
  • Key
for host = its name + k ey
  • f
secondary domain = its name + name
  • f
secondary domain + name
  • f
primary domain. 15
slide-16
SLIDE 16 All \Connecting" En tit y Sets Are W eak Beers Bars The- Beer Prices Bar The- The- Price BBP name addr name manf price
  • In
this sp ecial case, where bar and b eer determine a price, w e can
  • mit
price from the k ey , and remo v e the double diamond from ThePrice. 16