Lesson 12Object-Oriented DatabaseObject-Oriented Data ModelPowerPoint PresentationSlide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17OO Database Design by EER-to-OO MappingSlide 19Slide 20Slide 21Slide 22Slide 23Slide 24Lesson 12Object-Oriented Databases2Object-Oriented DatabaseOODBMDB is a collection of objectseach object represents a physical entity and an idea of interest to the DB application new trend in data modeling and DB processingGoal of Object-Oriented Data Modelingmaintain direct correspondence between real-world and database objectsuse concepts of class or abstract data type to encapsulate structural properties & operations on types of objects3Object-Oriented Data ModelObjectsencapsulate code & data into a single unitinteract w/ others by message passingconsist of variables that contain data for the objects; the value of each variables by itself is an objectstate of an object: set of values for the attribute called instance variable of the objectcontain methods: a method is a body of code, also called behavior of an objectflexible in modifying the definitions (e.g., methods) & variables of objects (e.g., referencing)4Object-Oriented DatabasesStudent FacultySpouseNameAddressStreetCityStateSSNOAdvisesTeachesFnameSal_HistYearSalaryFIDHasSnameBirthdateFigure. An Entity Relationship Schema DiagramNM1N115Object-Oriented DatabaseStudent FacultySpouseNameAddressStreetCityStateSSNOAdvisesTeachesFnameSal_HistYearSalaryFIDHasSnameBirthdateNM1N11Student(Name, Address(Street, City, State), SSNO) Faculty(Fname, Sal_Hist(Year, Salary), FID) Advises(SSNO, FID) Teaches(SSNO, FID) Spouse(Sname, Birthdate)Has(FID, Sname)Figure. The Structure of a Nested Relational Database Schema NRDS6Object-Oriented DatabaseFigure. An Instance of the Entity Relationship SchemaSSNO = 721009897Address(Street, City, State) = (90 N 70 E, Provo, Utah)Name = Susan TangSSNO = 123456789Address(Street, City, State) = (123 Perry, Orem, Utah)Name = Joe YoungFname = David HaysSal_Hist(Year, Salary) ={ (1991, 23K), (1994, 27K) }FID = 5624Fname = Chris SmithSal_Hist(Year, Salary) = { (1989, 25K), (1993, 30K) }FID = 2134Sname = Mary SmithBirthday = July 15, 1955s1f2a1a2t1s2f1h1sp17Object-Oriented DatabasesType Date: tuple (Month: integer, Day: integer, Year: integer);Class Student type tuple (SSNO: string, /* key */ Name: string, Address: tuple (Street: string, City: string, State: string), Advisor: Faculty, Teachers: set (Faculty))endFigure. The structure of an Object- Oriented Database Schema OODSStudent FacultyNameAddressStreetCityStateSSNOAdvisesTeachesFnameSal_HistYearSalaryFIDNM1N8Object-Oriented DatabasesClass Faculty type tuple ( FID: string, /* key */ Fname: string, Sal_Hist: set ( tuple( Year: integer, Salary: real) ), Advisees: set (Student), Teaches: set (Student), Spouse_of: Spouse) method Add_advisee (Std: Student), Average_salary, Raise_curr_salary (Percent: real)EndClass Spouse type tuple ( Sname: string, /* key */ Birthdate: Date, Spouse_of: Faculty) method Compute_ageend Figure. The structure of an Object- Oriented Database Schema OODSFacultySpouseFnameSal_HistYearSalaryFIDHasSnameBirthdate119name Susan_Tang: Student; /* a persistent root to hold a single Student object */name Joe_Young: Student; /* a persistent root to hold a single Student object */name David_Hays: Faculty; /* a persistent root to hold a single Faculty object */name Chris_Smith: Faculty; /* a persistent root to hold a single Faculty object */name Mary_Smith: Spouse; /* a persistent root to hold a single Spouse object */Susan_Tang->SSNO = “721009897”,Susan_Tang->Name = “Susan Tang”,Susan_Tang->Address = tuple(Street: “90 N 70 E”, City: “Provo”, State: “Utah”),Susan_Tang->Advisor = David_Hays;Joe_Young->SSNO = “123456789”,Joe_Young->Name = “Joe Young”,Joe_Young->Address = tuple(Street: “123 Perry”, City: “Orem”, State: “Utah”),Joe_Young->Advisor = Chris_Smith,Joe_Young->Teachers = set(Chris_Smith);David_Hays->FID = “5624”,David_Hays->Fname = “David Hays”,David_Hays->Sal_Hist = set ( tuple (Year: 1991, Salary: 23K), tuple (Year: 1994, Salary: 27K)),David_Hays->Advisees = set (Susan_Tang);Chris_Smith->FID = “2134”,Chris_Smith->Fname = “Chris Smith”,Chris_Smith->Sal_Hist = set ( tuple (Year: 1989, Salary: 25K), tuple (Year: 1993, Salary: 30K)),Chris_Smith->Advisees = set (Joe_Young),Chris_Smith->Teaches = set (Joe_Young),Chris_Smith->Spouse_of = Mary_Smith;Mary_Smith->Sname = “Mary Smith”,Mary_Smith->Birthdate = tuple (Month: 7, Day: 15, Year: 1995),Mary_Smith->Spouse_of = Chris_Smith;Figure. An Instance of OODS10method body Add_advisee(std: Student) in class Faculty{self->Advisees += set(std); /* += is the set union operation used to add std to a set of advisees */}method body Average_salary: float in class Faculty{float sum = 0;int cnt = 0;for (fac in self->Sal_Hist) { sum += fac->salary; /* add up salary */ cnt++; }return(sum/cnt);}method body Compute_age: integer in class Spouse /* Calculate a spouse’s age, */{ /* using spouse’s birthday and today’s date */int i = 0;Date d = today(); /* self: object for which the method is invoked */if (d->month < self->birthday->month || (d->month == self->birthday->month && d->day < self->birthday->day)) - - i;return(d->year - self->birthday->year + i);}method body Raise_curr_salary(percent: float): float in class Faculty{Date d = today();for (fac in self->Sal_Hist) /* self: object for which the method is invoked */ if (d->year == fac->year) { fac->salary = fac->salary * (1 + percent); break; }} Figure. Definitions of Methods in OODS using O2C11Define class Employee:type tuple( name: string, ssn: string, birthdate: Date, sex: char, dept: Department );operations age(e: Employee): integer, create_new_emp: Employee, destroy_emp(e: Employee): boolean;define class Departmenttype tuple( dname: string, dnumber: integer, mgr: tuple (manager: Employee, startdate: Date), locations: set(string), employees: set(Employee), projects: set(Project) )operations
View Full Document