Object-Oriented Analysis and Design
Lecture 14: Database Design
Objectives: Database Design
Define the purpose of Database Design and
where in the lifecycle it is performed
Explain how persistent classes map to the
data model
Learn how to distribute class behavior to
the database
Object Oriented Analysis and Design 2
Database Design in Context
[Early
Elaboration [Inception
Iteration] Iteration (Optional)]
Define a Candidate Perform
Architecture Architectural
Synthesis
Analyze Behavior
(Optional)
Refine the
Architecture
Database Database
Define Design the Designer Design
Components Database
Object Oriented Analysis and Design 3
Database Design Overview
Supplementary
Specifications
Database
Use-Case Realization Design
Data Model
Project Specific
Guidelines
Object Oriented Analysis and Design 4
Database Design Steps
Map persistent design classes to the data
model
Distribute class behavior to the database
Object Oriented Analysis and Design 5
Database Design Steps
Map persistent design classes to the data
model
Distribute class behavior to the database
Object Oriented Analysis and Design 6
Relational Databases and Object Orientation
RDBMS and Object Orientation are not entirely
compatible
RDBMS
• Focus is on data
• Better suited for ad-hoc relationships and reporting
application
• Expose data (column values)
Object Oriented system
• Focus is on behavior
• Better suited to handle state-specific behavior where
data is secondary
• Hide data (encapsulation)
Object Oriented Analysis and Design 7
The Relational Data Model
Relational model is composed of
Entities
Relations
Entity
Relation
products
ORDER LINE ITEM
Order_Id LineItem_Id
lineItems
Description
Price PRODUCT
order Quantity
lineItem Product_Id
Product_Id
Order_Id Name
Price
Columns
Object Oriented Analysis and Design 8
The Object Model
The Object Model is composed of
Classes (attributes)
Associations
LineItem
Order +lineItems - quantity : Integer
- number : Integer
+order - number : Integer
1..*
1
Product
- number : Integer
- description : String
- unitPrice : Double
Software Product Hardware Product
- version : Double - assembly : String
Object Oriented Analysis and Design 9
Persistence Frameworks
The challenge:
Changes should not break the Business
model Object
Model
The solution: An object-relational
framework that
Encapsulates the physical data
•Compact interfaces
store •Object-relational translation
Provides object translation services •Encapsulates data store
The importance of the
framework Relational
Database
30% of development time is spent
in accessing an RDBMS
Maintenance can be 60% of total
cost
Object Oriented Analysis and Design 10
Object-Relational Framework: Characteristics
Performance
Decomposing objects to data
Composing objects from data
Minimize design compromises
Limit changes to object and relational models
Extensibility
15%-35% of the framework needs to be
designed as an extensible framework
Object Oriented Analysis and Design 11
Object-Relational Frameworks: Characteristics (cont.)
Documentation of the API
Support for common object-relational
mappings
Persistence interfaces
Examples are save, delete, and find
Object Oriented Analysis and Design 12
Common Object-Relational Services
Patterns are beginning to emerge for
object-relational applications
CORBA Services specification
• Persistence
• Query
• Transactions
• Concurrency
• Relationships
Refer to the appropriate CORBA specifications for further details.
Object Oriented Analysis and Design 13
Mapping Persistent Classes to Tables
In a relational database
Every row is regarded as an object
A column in a table is equivalent to a persistent
attribute of a class
Attributes from object type
Student
- name : String
- address : String Name Student_ID
- studentID : Long Thomas Stuart 123456
Object Instance
Object Oriented Analysis and Design 14
Mapping Associations Between Persistent Objects
Associations between two persistent
objects are realized as foreign keys to the
associated objects.
A foreign key is a column in one table that
contains the primary key value of associated
object Course Offering table
Number Course_ID
CourseOffering 678 456789
- number : String
Foreign Key
0..*
Course table Primary Key
Course
- name Name Description Number
1 - description
- number Math 101 Algebra 456789
Object Oriented Analysis and Design 15
Mapping Aggregation to the Data Model
Aggregation is also modeled using foreign
key relationships
The use of composition implements a
cascading delete constraint
Student table
Student. Student_ID
- studentID : int
123456
1 Primary Key
0..*
Schedule table Foreign Key
Schedule
- semester : Semester Student_ID Semester
123456 Spring 2001
Object Oriented Analysis and Design 16
Modeling Inheritance in the Data Model
A Data Model does not support modeling
inheritance in a direct way
Two options:
Use separate tables (normalized data)
Duplicate all inherited associations and
attributes (de-normalized data)
Object Oriented Analysis and Design 17
Database Design Steps
Map persistent design classes to the data
model
Distribute class behavior to the database
Object Oriented Analysis and Design 18
What Are Stored Procedures?
A stored procedure is executable code that
runs under the RDBMS
Two types of stored procedures:
Procedures: Executed explicitly by an
application
Triggers: Invoked implicitly when some
database event occurs
Object Oriented Analysis and Design 19
Map Class Behavior to Stored Procedures
Determine if any operations can be
implemented as a stored procedure
Candidates:
Operations that deal with persistent data
Operations in which a query is involved in a
computation
Operations that need to access the database to
validate data
Object Oriented Analysis and Design 20
Example: Map Class Behavior to Stored Procedures
Class Candidate Operations
Student. • getTuition
+ getTuition() • addSchedule
+ addSchedule()
+ getSchedule()
+ deleteSchedule() • getSchedule
+ hasPrerequisites()
# passed() • deleteSchedule
+ getNextAvailID()
+ getStudentID()
+ getName()
• getStudentID
+ getAddress()
• getName
• getAddress
Object Oriented Analysis and Design 21
Checkpoints: Database Design
Have all persistent classes been
mapped to database structures?
Have stored procedures and
triggers been defined?
Does the persistence mechanism
use stored procedures and
database triggers consistently?
Object Oriented Analysis and Design 22
Review: Database Design
What is the purpose of the Database
Design?
What comprises a relational data model?
What are the components of an object
model?
When mapping persistent classes to tables,
what is every row in a table regarded as?
What is every column equivalent to?
What are stored procedures?
Object Oriented Analysis and Design 23
Object Oriented Analysis and Design 24