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 with to distinguish. r oles � Married h usband wife Drink ers Husband Wife d d 1 2 d d 3 4 � � � � � � 2
Buddies 1 2 Drink ers Buddy1 Buddy2 d d 1 2 d d 1 3 d d 2 1 d d 2 4 � � � � � � Notice is symmetric, not. Buddies Marrie d � ✦ No w a y to sa y \symmetric" in E/R. ✦ But in ODL, symmetric relations are their o wn in v erse. 3
Roles in ODL No problem; names of 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 is optional when the Drinkers:: � in v erse is a relationship of the same class. Design Issue Should w e replace and b y one husband wife relationship spouse ? 4
Sub classes Sub class = sp ecial case = few er en tities/ob jects = more prop erties. Example: Ales are a kind of b eer. In addition � to the prop erties (= attributes, relationships, metho ds) of b eers, there is a \color" attribute for ales. ODL Sub classes F ollo w name of sub class b y colon and its sup erclass. interface Ales:Beers { attribute String color; } Ob jects of the class acquire all the Ales � attributes and relationships of the class. Beers 5
E/R Sub classes triangles indicate the sub class relation. isa � name manf Beers isa color Ales 6
Di�erence in Sub class Viewp oin ts In ODL, an en tit y is in exactly one class. � ✦ It inherits prop erties of 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 of the prop erties of these classes. The distincti on matters later, when w e con v ert � ODL and E/R to relations. name manf Beers isa P ete's Ale color Ales 7
Multiple Inheritance Theoreticall y , a class/E.S. could b e a sub class of sev eral classes. name manf name manf Beers Wines isa isa Grap e Beers 8
Problems Ho w should con�icts b e resolv ed? Example: means gro w er for wines, manf � b ottler for b eers. What do es mean for manf \grap e b eers"? E/R m ute on m ultiple inheritance; ODL lea v es � it to implemen ter. 9
Keys = set of attributes whose v alues can b elong to at most one en tit y or ob 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 ose is k ey for ers . name Be � name manf Beers isa color Ales Beer name is also k ey for ales. � ✦ In general, k ey at ro ot (no m ultiple inheritance!) is k ey for all. 10
Keys in ODL Indicate with follo wing the class name, and key(s) a list of 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 of a k ey , and also group to the declared k eys. key ✦ Th us, = \one (key( a ; a ; : : : ; a )) 1 2 n k ey consisting of all attributes." n = \eac h is a k ey (key a ; a ; : : : ; a ) a 1 2 n i b y itself. Example: � interface Beers (key name) { attribute string name ... 11
A Multiattribute Key dept n um b er hours ro om Courses interface Courses (key (dept, number), (room, hours)) { ... E/R requires exactly one k ey , but ODL allo ws � zero or more k eys. V ery Imp ortan t : In ODL, \ob ject iden tit y" � serv es to distinguish ob jects, so no key at al l is essary . ne c 12
W eak En tit y Sets Sometimes an E.S.'s k ey comes not (completely) from its o wn attributes, but from the k eys of one or more E.S's to whic h the �rst is link ed b y a man y-one relationship. Called a E.S. we ak � 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 of its k ey . Use of man y-one relationship (includes 1-1) � essen tial. ✦ With a man y-man y , w e w ouldn't kno w whic h en tit y pro vided the k ey v alue. V ery Imp ortan t : There is no suc h thing as a � \w eak class" in ODL. ✦ Because ob jects ha v e ob ject-iden tit y , classes don't need k eys, and therefore they don't need to \b orro w" k eys from related classes. 13
Example: Logins Login name = user name + host name, e.g., edu . ullman@shalmaneser .stan ford. A \login" en tit y corresp onds to a user name � on 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 only) + the name of the host (whic h is unique globally) . name name @ Logins Hosts 14
Example: Chain of \W eakness" Consider IP addresses consisting of a primary domain (e.g., edu ) sub domain (e.g., stanford ), and host (e.g. shalmaneser ). name name name 2ndary Primary Hosts In2 In1 Domains Domains Key for primary domain = its name. � Key for secondary domain = its name + name � of primary domain. Key for host = its name + k ey of secondary � domain = its name + name of secondary domain + name of primary domain. 15
All \Connecting" En tit y Sets Are W eak BBP The- The- The- Bar Beer Price Bars Beers Prices name addr name manf price In this sp ecial case, where bar and b eer � determine a price, w e can omit from price the k ey , and remo v e the double diamond from ThePrice . 16
Recommend
More recommend