www.covenantuniversity.edu.
ng
Introduction to Database
Systems
Lecture 4
CSC 825/MIS 823/BIF 846
Prof. Olufunke Oladipupo
+2348033319370
1
Lecture Outline
▪ Object-Oriented Data Modelling [OODM]
– Introduction
– Unified Modeling Language
– Encapsulation.
– Associations
– Generalization & Specialization
– Polymorphism
– Object Definition Language
2
Lecture Objectives
▪ At the end of this lecture,
– The fundamental concepts of the Object Oriented
Data Model (OODM) should be fully understood.
– There should be a good understanding of how to
model problems cases and scenarios using the
OODM.
– Introduced to Object Definition Language and
Object Query Language
3
Introduction
▪ OODM is becoming increasingly popular because of
its ability to thoroughly represent complex
relationships, data and data processing in a
consistent notation.
▪ An OODM is built around object.
▪ An object encapsulates both data and behaviour.
▪ It can be used not only for data modeling, but also
for modeling behaviour.
Introduction
▪ To thoroughly model any real-world
system, you need to model both the data,
and the processes and behavior that act
on the data.
▪ The object-oriented modeling approach
provides a powerful environment for
developing complex systems.
Motivation for OODM
▪ The ability to tackle more challenging problem
domains;
▪ Improved communication between the users,
analysts, designers, and programmers;
▪ Increased consistency among analysis,
design, and programming activities;
▪ Explicit representation of commonality among
system components;
Motivation for OODM
▪ Robustness of systems;
▪ Reusability of analysis, design, and
programming results;
▪ Increased consistency among all the
models developed during object-
oriented analysis, design, and
programming.
Unified Modeling Language
▪ Unified Modeling Language (UML) is a set of
graphical notations supported by a common
metamodel.
▪ This is widely used both for business modeling and
for specifying, designing, and implementing
software systems artifacts.
▪ For representing a complex system effectively, the
model you develop must consist of a set of
independent views or perspectives.
Unified Modeling Language
▪ UML allows you to represent multiple perspectives
of a system by providing different types of
graphical diagrams, such as
– the use-case diagram,
– class diagram,
– state diagram,
– sequence diagram,
– component diagram, and
– deployment diagram.
Unified Modeling Language
If these diagrams are used correctly
together in the context of a well-
defined modeling process, UML
allows you to analyze, design, and
implement a system based on one
consistent conceptual model.
Class diagram
▪ This is one of the static diagrams in UML, addressing
primarily structural characteristics of the domain of
interest.
▪ The class diagram allows the designer to capture the
responsibilities that classes can perform, without any
specifics of the behaviors.
▪ UML class diagrams can be used for multiple purposes
at various stages of the system life cycle model .
Class diagram
A diagram that shows the
static structure of an object-
oriented model: the object
classes, their internal
structure, and the relationships
in which they participate.
A Class
A class is an entity that has a well-
defined role in the application domain
about which the organisation wishes to
maintain state (attributes and
relationship), behaviour (how an object
acts or reacts) and identity.
A Class
▪ A class is a concept, abstraction, or thing that
makes sense in an application context.
▪ A class could be a tangible or visible entity( e.g a
person, place, or thing).
▪ It could be a concept or event (e.g.,
Department, performance, marriage,
registration, etc);
▪ or it could be an artefact of the design
process(e.g., User Interface, controller,
scheduler, etc)
An Object
An object is an instance of a class (e.g. a
particular person, place or thing) that
encapsulates the data and behaviour we
need to maintain about the object.
▪ All objects have a persistent identity.
▪ A class of object shares a common set of
attributes and behaviours.
An Object
▪ The state of an object encompasses its properties
(attributes and relationships) and the values those
properties have,
▪ Its behaviour represents how an object acts and
reacts.
▪ An object's state is determined by its attribute values
and links to other objects.
▪ An object's behaviour depends on its state and the
operation being performed.
An Operation
An operation is simply an action that one object
performs on another to get a response to a request.
An operation is a function or a service that is
provided by all the instances of a class.
▪ It is only through such operations that other objects can
access or manipulate the information stored in an object.
An Operation
The operations, therefore provide an
interface to a class.
The interface presents the outside
view of the class without showing its
internal structure or how its
operations are implemented.
Encapsulation.
The technique of hiding the
internal implementation
details of an object from its
external view.
Example
▪ Consider an example of the student class and a
particular object in this class is Mary Jones
– The state of this object is characterised by its
attributes Name, DOB, Years, address, and phone,
and the values these attributes currently have.
▪ UML class and object diagrams
(a) Class diagram showing two classes
(b) Object diagram with two instances
(a)
(b)
Associations
This is a named relationship between or
among instances of object classes.
The end of an association where it connects to a class
is called an association role.
A specification that indicates how many objects
participate in a given relationship is called Multiplicity
Examples
Unary
Relationships *
Person Manage
0..1
0..1 s
Person Manager
Marries
0..1 A person marries one A person manages
or no person many persons
A person can be Many persons is
married by one or no managed by one or no
person person
Association relationships
Association Class
An association that has attributes or
operations of its own or that participates in
relationship with other classes.
For instance
▪ The attributes Semester and grade and the operation
CheckEligibility belong to many-to-many association
between Student and Course.
▪ In OODM you have the option of showing the name of an
association class on the association path, or the class
symbol or both.
Association Class
▪ When an association has only attribute, but does not have
any operations or does not participate in other
associations, the recommended option is to show the
name on the association path, but omit it from the
association class symbol to emphasize its "association
nature“
– For example – Tutors Association
▪ On the other hand if it has both attribute and operations,
then we include it in the association class
– For example - Registration Association
Association class and link
object
Class Generalization &
Specialization
In OODM classes that are
generalized are called
subclasses, and
the class they are generalized
into is called a superclass.
Examples of generalization, inheritance, and
constraints
(a) Employee superclass with three subclasses
Abstract class
A class that has no direct
instances
but whose descendants may
have
direct instances.
Concrete class
A class that can have
direct
instances.
(b) Abstract Patient class with two
concrete subclasses
Class-scope attribute
An attribute of a class that
specifies a value common to
an entire class rather than a
specific value for an instance.
Polymorphism
The ability of an operation
with the same name to
respond in different ways
depending on the class
context.
Polymorphism, abstract operation, class-
scope attribute
Note
▪ It is important to note that although the Graduate
Student and Undergraduate Student classes share
the same calcTuition operation, they might
implement the operation in quite different ways.
▪ For example, the method that implements the
operation for a graduate student might add a special
graduate fee for each course the student takes.
▪ The fact that an operation with the same name may
respond in different ways depending on the class
context is known as polymorphism.
Aggregation
An aggregation expresses a Part-of relationship
between a component object and an aggregate object.
▪ It is a stronger form of association relationship (with
the added “part-of” semantics)
▪ It is represented with a hollow diamond at the
aggregate end.
Example of aggregation
Composition
A part-of relationship in which
parts belong to only one whole
object and live and dies with the
whole object.
Object Oriented Database
Development
Objective:
How OODM can be directly implemented using Object
Oriented Database Management System (ODBMS)
– For defining and querying an OODB we will adopt
Object model proposed by Object Database
management group (ODMG).
– For developing logical schema : Object definition
Language
– For data Manipulation: Object Query Language.
Object Definition Language
▪ In ODL, a class is specified using the class keyword; an
attribute is specified using the attribute keyword.
▪ Student and Course classes might be defined as
follows
class Student{
attribute string name;
attribute Date dateofBirth;
attribute string address;
attribute string phone;
// plus relationship and operations…
};
Object Definition Language
class Course{
attribute string courseCode;
attribute string courseTitle;
attribute short creditHrs;
//plus relationship and operations…
}
• In addition to the standard data types provided by
ODL, you can define structures yourself by using
struct keyword.
• e.g you can define a structure called address that
consist of four components- street, city, state, and
zipCode-- all of which are string attributes
struct Address{ The ODL for student
can now be as
string street;
follows
string city;
string state;
string zipCode;
};
class Student{
attribute string name;
attribute Date dateofBirth;
//User-defined structures attributes
attribute Address address;
attribute string phone;
// plus relationship
//Operations
short age(); // query operation
float gpa(); // query operation
boolean register-for (string course, short sec, string
Semester) //Reupdate
turn operation
Type
};
Binary relationship between Student & CourseOffering
Student * Takes * CourseOffering
Takenby
BelongsTo
1
Offers
*
Course
The ODMG Object Model requires that a relationship be
class Student{ specified in both directions. In ODL, the inverse keyword is
attribute string name; used to specify the relationship in the reverse direction.
The inverse of “takes” is “taken by” from CourseOffering to
attribute Date dateofBirth;
Student. In the class definition for Student, we have named
//User-defined structures attributes
this traversal path (takenby), proceeded by the name of
the class from where the path originates (CourseOffering),
attribute Address address;
along with a double colon(::).
attribute string phone;
// relationship between Student and CourseOffering
relationship set <CourseOffering>takes inverse
CourseOffering:: takenby;
//Operations
short age();
float gpa();
boolean register-for (string course, short sec, string
Semester)
};
Generalization Example
▪ ODL allows the representation of
generalization relationship using the
extends keyword
▪ Using the Hourly Employee, Salaried
Employee, and Consultant – are generalized
into subclass called Employee. The ODL
schema corresponding to the class diagram
might be as follows
class Employee{
(extent employees)
attribute short empName;
attribute string empNo;
attribute Address address;
attribute Date dateHired;
void printLabel();
};
class HourlyEmployee extends Employee{
(extent hrlyEmps)
attribute float hourlyRate;
float computeWages();
};
class SalariedEmployee extends Employee{
(extent salarieedEmps)
attribute float annualSalary;
attribute boolean stockOptions;
void contributePension();
}
class Consultant extends Employee{
(extent consultants)
attribute short contractNumber;
attribute float billingRate;
float computeFees();
};
Creating Object Instances Example
▪ When a new instance of a class is created, a
unique object identifier is assigned.
▪ You may specify an object identifier with one
or more unique tag names.
1. Creating a new student object and initialize
some of its attributes.
Jane student (name: “Jane Fred”,
dateOfBirth: 4/5/90);
Creating Object Instances Example
2. How to represent multivalue attribute
Dan employee (empId: 0089, name: “Dan James”,
skill: {“Database designer”, “System Analyst”});
3. Expressing that Jane took three courses in
Alpha semester
Jane student (takes: { CSC 835A, CSC 876,CSC
817});
Class Activity 1
The following tables form part of a database held in a
relational DBMS
Hotel(hotelNo, hotelName, city)
Room(roomNo, hotelNo, type, price)
Booking(hotelNo, guestNo, dateFrom, dateTo,
roomNo)
Guest(guestNo, guestName, guestAddress)
• Hotel contains hotel details and hotelNo is the primary key
• Room contains room details for each hotel and (roomNo, hotelNo)
forms the primary key
• Booking contains details of booking and (hotelNo, guestNo,
dateForm) forms the primary key;
• Guest contain guest details and guestNo is the primary key 53
Questions
i. For the relations, suggest a number of methods that
may be applicable and produce an object-oriented
schema for each of the relations
ii. Represent the schemas in a class diagram
iii. Write the ODL for the Hotel schema;
54
Lecture Reference
▪ Ramakrishnan, R., Gehrke, J.: Database Management Systems. USA:
McGraw Hill Companies (2000)
▪ Elmasri, R., & Navathe, S. (2000). Fundamentals of database
systems (3rd ed.). Reading, Mass.: Addison-Wesley.
▪ Hoffer, J. A., Prescott, M. B., & McFadden, F. R. (2005). Modern database
management. Upper Saddle River, N.J: Pearson/ Prentice Hall.
▪ Connolly, T. M., & Begg, C. E. (2002). Database systems: A practical
approach to design, implementation, and management. Harlow,
England: Addison-Wesley
▪ http://pages.cs.wisc.edu/~dbbook/openAccess/thirdEdition/solutions/an
s3ed-oddonly.pdf
▪ https://gyires.inf.unideb.hu/GyBITT/03/
55