Download presentation
Presentation is loading. Please wait.
Published byLesley Farmer Modified over 9 years ago
1
Database Design – Lecture 12 Object Oriented Database Design cont’d
2
2 Lecture Objectives Class Review Relationships Associations Aggregation/Composition Inheritance
3
3 Classes ClassName attributes operations() Structure: Attribute names start with a small capital. If an attribute name is made up of multiple words, there is no space between the words and each subsequent word begins with a capital letter Operation names start with a small capital. If an operation name is made up of multiple words, there is no space between the words and each subsequent word begins with a capital letter
4
4 Classes Class Example Employee name ADDRESS dob telephone DEPENDENT BENEFICIARY Address streetNumber street city province postalCode EMPLOYEE Denotes another abstract data Type (ADT); or another class Dependent name Dob EMPLOYEE Beneficiary name Relationship EMPLOYEE
5
5 Classes Class Example (different notation) Employee name address dob telephone dependents beneficiary Address streetNumber street city province postalCode Denotes another abstract data Type (ADT); or another class Dependent name dob Beneficiary name relationship employee
6
6 Lecture Objectives Classes Relationships Associations Aggregation/Composition Inheritance
7
7 Relationships 1:1 I.e. An employee has 1 address and an address belongs to 1 employee Address streetNumber street city province postalCode employee 1 Employee name address 1 dob telephone dependent beneficiary Denotes a mandatory participation
8
8 Relationships 1:M I.e. An employee has 0 or more dependents and a dependent belongs to 1 employee Employee name address 1 dob telephone dependent M beneficiary (no line) denotes an optional participation Dependent name dob employee 1
9
9 Relationships M:N (option 1) I.e. An employee has 1 or more beneficiaries and a beneficiary belongs to 1 or more employees employee M Beneficiary name percent relationship Employee name address 1 dob telephone dependent M beneficiary M
10
10 Relationships M:N (option 2) I.e. An employee has 1 or more beneficiaries and a beneficiary belongs to 1 or more employees Create an intersection class with associated attributes employeeBeneficiary M Beneficiary name Employee name address 1 dob telephone dependent M employeeBeneficiary M employee 1 EmployeeBeneficiary percent relationship beneficiary 1
11
11 Relationships – two notations Employee name address 1 dob telephone dependent M beneficiary M Dependent name dob employee 1 employee M Beneficiary name percent relationship Note how we can show M:N relationship in OODM
12
12 Lecture Objectives Classes Relationships Associations Aggregation/Composition Inheritance
13
13 Associations An association between two classes indicates the possibility that links will exist between the objects of the classes The links provide the ability for message passing to happen Links can be uni-directional or bi-directional associations as well as more complex type links such as aggregation/composition – need to clearly understand the navigability of the association Links also show multiplicity (1:1; 1:M; M:N)
14
14 Associations 1:1 Can be bi-directional or uni-directional which shows the direction a message can be sent Bi-directional – message goes in both directions Address streetNumber street city province postalCode employee 1 Employee name dob address 1 1 1 Lives at Bi-directional; message goes in both directions
15
15 Associations 1:1 Uni-directional – message goes in direction of arrow only Note there is no reference to the Employee class in the Address class Address streetNumber street city province postalCode Employee name dob address 1 1Lives at Uni-directional; message goes in one direction only **Note there is no reference to employee abstract data type (ADT) in the Address class
16
16 Associations 1:M Can be bi-directional or uni-directional What would change if we made it a uni-directional association? Employee name address 1 dob telephone dependent M beneficiary Dependent name dob employee 1 1 0..n Can have
17
17 Associations 1:M Can be bi-directional or uni-directional What would change if we made it a uni-directional association? – see below Employee name address 1 dob telephone dependent M beneficiary Dependent name dob employee 1 0..n Can have **Note there would be no reference to employee abstract data type (ADT) in the Dependent class
18
18 Associations M:N Can be bi-directional or uni-directional What would change if we made it a bi-directional association? Employee name address 1 dob telephone dependent M beneficiary M Beneficiary name relationship 1..n Can have
19
19 Associations M:N Can be bi-directional or uni-directional What would change if we made it a bi-directional association? – see below Employee name address 1 dob telephone dependent M beneficiary M Beneficiary name relationship employee M 1..n Can have **Note a reference to employee abstract data class would be added
20
20 Lecture Objectives Classes Relationships Associations Aggregation/Composition Inheritance
21
21 Aggregation/Composition A special kind of association. A whole (assembly) –part (components) relationship An instance of one class may consist of, or include instances of another class. The aggregate class assumes a special role for delegation of responsibility and leadership The number of ‘parts’ are shown by multiplicity Aggregations are usually 1-to-many (aggregate to components) but not always
22
22 Aggregation/Composition A “has a” or “consists of” relationship A Book contains Chapters Book Chapter contains Aggregate or whole Components or part Diamond symbol denotes an aggregation
23
23 Aggregation/Composition Example : An invoice has invoice items A car has tires A company has contacts
24
24 Aggregation/Composition Composition is a special kind of aggregation. The component parts depend on the aggregate for existence—delete the aggregate and the components disappear BookChapter contains Aggregate or whole Component or part Filled in diamond symbol denotes a composition
25
25 Aggregation vs Association Which of these are composition? An invoice has invoice items A car has tires A company has contacts
26
26 Aggregation vs Association Show compositions in OODM only – aggregations can be shown as associations only If you are not clear on the relationship between two classes, assume it is only an association – do not assume it has to be aggregation, composition or inheritance!
27
27 Lecture Objectives Classes Relationships Assoications Aggregation/Composition Inheritance
28
28 Inheritance Classes are organized into a hierarchy Hierarchy equates to inheritance Inheritance allows an object to inherit the data structure and behavior of the classes above it In OO systems, all objects are derived from the super class Object or the Root class
29
29 Inheritance Single Inheritance (~Hierarchical Structure) A class has only one immediate (parent) superclass above it
30
30 Inheritance Multiple Inheritance (~Network Structure) A class has more than one immediate (parent) superclass above it
31
31 Inheritance Defining Inheritance Two approaches: Generalization Look for common attributes and operations in a set of classes and create a new superclass and place the common attributes and operations into the superclass Specialization Create two or more subclasses to associate attributes and methods to
32
32 Inheritance Defining Inheritance Generalization Look for common attributes and operations in a set of classes and create a new superclass and place the common attributes and operations into the superclass Two classes that share common attributes and operations create a new class called StaffMember and move common attributes and operations to new superclass
33
33 Inheritance Generalization
34
34 Inheritance Defining Inheritance Specialization One class however, it may be determined that there are different types of staff members resulting in the creation of some sub classes
35
35 Inheritance Defining Inheritance Specialization
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.