0% found this document useful (0 votes)
14 views14 pages

Chapter 5 2013 5

Uploaded by

Tegbaru Tamene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views14 pages

Chapter 5 2013 5

Uploaded by

Tegbaru Tamene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

CHAPTER FIVE

5. Object Oriented Database Management Systems(OODBMS)


Learning Objectives: This chapter provides an overview of object oriented database management
system. After completing this chapter the reader should be familiar with the following concepts:
• Object-Oriented Database Management System
• Object Oriented Concepts
• Object Oriented Data modeling and E-R diagramming
• Storing objects in relational database systems

5.1. OODMS
An object-oriented database management system (OODBMS) is a database management system
that supports the creation and modeling of data as objects. In OODBMS data is stored in form of
objects, which are instances of classes. These classes and objects together make an object-oriented
data model. OODBMS also includes support for classes of objects and the inheritance of class
properties, and incorporates methods, subclasses and their objects. OODBMS allows programmers
to enjoy the consistency that comes with one programming environment because the database is
integrated with the programming language and uses the same representation model. Certain object-
oriented databases are designed to work with object-oriented programming languages such as C++,
Python, Java, C#, PHP and so on. Object-oriented database technology is a marriage of object-
oriented programming and database technologies. It handles a mix of data types (since OODBMS
permits new data definition). OODBMS follows Object Oriented rules and also follows DBMS
rules.

OODB: A persistent and sharable collection of objects defined by an OODM. Object-Orientation


= abstract data types + inheritance + object identity;
OODBMS = object-orientation + database capabilities. It is the manager of an OODB.
OODBMS must, at a minimum, satisfy:
1. It must provide database functionality;
2. It must support object identity;
3. It must provide encapsulation;
4. It must support objects with complex state.

1
Object Orientation is a set of design and development principles. Based on autonomous computer
structures known as objects. Object Oriented(OO) Contribution areas: Programming Languages,
Graphical User Interfaces, Databases, Design and Operating Systems.
5.1.1. Evolution of Data Models
First Generation DBMS: Network and Hierarchical. Required complex programs for even simple
queries. Minimal data independence. No widely accepted theoretical foundation.
Second Generation DBMS: Relational DBMS:Helped overcome these problems.
Third Generation DBMS: OODBMS and ORDBMS.

5.1.2. OODBMS Advantages


• More semantic information
• Support for complex objects
• Extensibility of data types (user defined data types)
• May improve performance with efficient caching
• Versioning
• Polymorphism: one operation shared by many objects and each acting differently
• Reusability
• Inheritance speeds development and application
• Potential to integrate DBMSs into single environment

2
• Relationship between objects is represented explicitly supporting both navigational
and associative access to information.
5.1.3. OODBMS Disadvantages
• Strong opposition from the established RDBMSs
• Lack of business data design and management tools
• Lack of compatibility between different OODBMSs
• Lack of theoretical foundation
• Throwback to old pointer systems
• Lack of standard ad hoc query language
• No single data model
• Steep learning curve
• Low market presence
5.1.4. Components of Object-Oriented Data Model
The OODBMS is based on three major components, namely: Object structure, Object classes, and
Object identity. These are explained below:

1. Object Structure: The structure of an object refers to the properties that an object is made up of.
These properties of an object are referred to as an attribute. Thus, an object is a real-world entity
with certain attributes that makes up the object structure. The object structure is further composed
of three types of components: Messages, Methods, and Variables. These are explained below.
• Messages: A message provides an interface or acts as a communication medium between an
object and the outside world. A message can be of two types:
o Read-only Message: If the invoked method does not change the value of a variable, then
the invoking message is said to be a read-only message.
o Update Message: If the invoked method changes the value of a variable, then the invoking
message is said to be an update message.
• Methods: When a message is passed then the body of code that is executed is known as a
method. Whenever a method is executed, it returns a value as output. A method can be of two
types:
o Read-only Method: When the value of a variable is not affected by a method, then it is
known as the read-only method.

3
o Update-Method: When the value of a variable change by a method, then it is known as an
update method.
• Variables: It stores the data of an object. The data stored in the variables makes the object
distinguishable from one another.
2. Object Classes: An object which is a real-world entity is an instance of a class. Hence first we
need to define a class and then the objects are made which differ in the values they store but share
the same class definition. The objects in turn correspond to various messages and variables stored
in them. Example:-
class STUDENT
{ //variables
char name;
string address;
int id;
int salary;
//methods
char get_name();
string get_address();
int annual_salary();
};
In the above example, STUDENT is a class that holds the object variables and messages.

5.2. OO Data Model and E-R Data Model


OO Data Model: A (logical) data model that captures the semantics of objects supported in object-
oriented programming. Characteristics of OO Data Model:
• Supports complex objects • Exhibit inheritance
• Must be extensible • Supports object identity
• Supports encapsulation
OO Data Model vs. E-R Data Model Components

OO Data Model E-R Data Model


Type Entity definition
Object Entity Instance
Class Entity set
Instance variable Attribute
N/A Primary key
OID N/A

4
Class hierarchy E-R diagram

5.3. Drawbacks/Weaknesses of Relational DBMS


Poor Representation of “Real World” Entities: Normalization leads to relations that do not
correspond to entities in “real world”.
Semantic Overloading: Relational model is semantically overloaded. Representation of complex
relationship is difficult. E.g., M:N relationship is represented by adding one additional relation
(making the relation an entity). One cannot distinguish a relation from a relationship. Difficult to
distinguish different types of relationship.
Poor Support for Integrity and Enterprise Constraints: Many commercial BMS do not support
all integrity constraints. The relational model doesn’t support enterprise constraints it has to be
done on the DBMS.
Homogeneous Data Structure: Relational model assumes both horizontal and vertical
homogeneity. Horizontal Homogeneity each tuple of a relation have same number and type of
attributes. Vertical Homogeneity values of an attribute should come from same domain. Field value
should be atomic.

5
Limited Operations:RDBMs only have a fixed set of operations which cannot be extended. It
does not allow additional/new operations.
Difficulty Handling Recursive Queries: Extremely difficult to produce recursive queries.
Extension proposed to relational algebra to handle this type of query is unary transitive (recursive
query) closure operation.
Impedance Mismatch: Most DMLs lack computational completeness. To overcome this, SQL
can be embedded in a high-level 3GL. This produces an impedance mismatch - mixing different
programming paradigms. Estimated that as much as 30% of programming effort and code space is
expended on this type of conversion. Mixing of different programming paradigms and mismatch
between the languages used.
Poor navigational process: Access is based on navigating individual records from different
relations. RDBMSs are poor at navigational access.
Other Problems with RDBMSs: Transactions are generally short-lived and concurrency control
protocols not suited for long-lived transactions. Schema changes are difficult.

5.4. Comparison of RDBMS and OODBMS


RDBMS stands for Relational Database Management System. It is a database management system
based on the relational model i.e. the data and relationships are represented by a collection of inter-
related tables. Example, MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.
OODBMS is a DBMS where data is represented in the form of objects, as used in object-oriented
programming. OODB implements object-oriented concepts such as classes of objects, object
identity, polymorphism, encapsulation, and inheritance.
Criteria RDBMS OODBMS
Way of storing Stores data in Entities, defined as Stores data as Objects.
data tables hold specific information.
Data Handles comparatively simpler Handles larger and complex data than
Complexity data. RDBMS.
Grouping Entity type refers to the collection Class describes a group of objects that
of entity that share a common have common relationships, behaviors,
definition. and also have similar properties.
Data Handling RDBMS stores only data. Stores data as well as methods to use it.
Main Objective Data Independence from Data Encapsulation.
application program.
Key A Primary key distinctively An object identifier (OID) is an
identifies an object in a table. unambiguous, long-term name for any
type of object or entity.

6
5.5. Object Oriented Concepts
An OODBMS also supports inheritance in an extensive manner as in a database there may be many
classes with similar methods, variables and messages. Thus, the concept of the class hierarchy is
maintained to depict the similarities among various classes. The concept of encapsulation that is
the data or information hiding is also supported by an object-oriented data model. And this data
model also provides the facility of abstract data types apart from the built-in data types like char,
int, float. Object-oriented Programming Languages Goals:

• Easy-to-use development environment


• Powerful modeling tools for development
• Decrease in development time
• Make reusable code
Object-oriented concepts can be used in different ways Object-orientation can be used as a design
tool, and be encoded into. For example, a relational database analogous to modeling data with E-
R diagram and then converting to a set of relations. The concepts of object orientation can be
incorporated into a programming language that is used to manipulate the database.
Object-relational systems: add complex types and object-orientation to relational language.
Persistent programming languages: extend object-oriented programming language to deal with
databases by adding concepts such as persistence and collections. Persistent Programming
languages allow objects to be created and stored in a database and used directly from a
programming language. Allow data to be manipulated directly from the programming language no
need to go through SQL.
5.5.1. Abstraction
Process of identifying essential aspects of an entity and ignoring unimportant properties.
Concentrate on what an object is and what it does, before deciding how to implement it.
5.5.2. Encapsulation and Information Hiding
Encapsulation: Object contains both data structure and set of operations used to manipulate it.
• One of the main characteristics of OO languages and systems.
• Class encapsulates data and the operations that work on the data in a single package.
• Related to the concepts of abstract data types and information hiding in programming
languages.
• Encapsulation means data and operations are packaged under one name and can be reused as

7
one specification or program component.
Benefits of Encapsulation are:
• The internal implementation details of data and procedures are hidden from the outside world
(information hiding). This reduces the propagation of side effects when changes occur
• Data structures and the operations that manipulate them are merged in a single named entity-
the class. This facilitates component reuse
• Interfaces among encapsulated objects are simplified. An object that sends a message need not
be concerned with the detail of internal data structures. Interfacing is simplified and the system
coupling tends to be reduced.
Information Hiding: Separate external aspects of an object from its internal details, which are
hidden from outside. Allows internal details of an object to be changed without affecting
applications that use it, provided external details remain same. Provides data independence.
5.5.3. Objects and Attributes
Objects: Uniquely identifiable entity that contains both the attributes that describe the state of a
real-world object and the actions associated with it. Definition very similar to definition of an
entity, however, object encapsulates both state and behavior; an entity only models state.
Attributes: Contain current state of an object. Attributes can be classified as simple or complex.
Simple attribute can be a primitive type such as integer, string, etc., which takes on literal values.
Complex attribute can contain collections and/or references. Reference attribute represents
relationship. An object that contains one or more complex attributes is called a complex object.
Complex Objects: An object that consists of subobjects but is viewed as a single object. Objects
participate in a A-PART-OF (APO) relationship. Contained object can be encapsulated within
complex object, accessed by complex object’s methods. Or have its own independent existence,
and only an OID is stored in complex object.
Object Characteristics:
• Class Hierarchy: Superclass, Subclass
• Inheritance: Ability of object to inherit the data structure and behavior of classes above it
• Method Overriding: Method redefined at subclass
• Polymorphism: Allows different objects to respond to same message in different ways.
Object Classification:
• Simple: Only single-valued attributes and no attributes refer to other objects.

8
• Composite: At least one multi-valued attribute and no attributes refer to other object
• Compound: At least one attribute that references another object
• Hybrid: Repeating group of attributes and at least one refers to another object
5.5.4. Object Identity
An OO database system provides a unique identity to each independent object stored in the
database. The main property required of an OID is that it be immutable; that is, the OID value of
a particular object should not change. This preserves the identity of the real-world object being
represented. Object identifier (OID) assigned to object when it is created that is:
• System-generated. • Invisible to the user (ideally).
• Unique to that object. • Invariant.
• Independent of the values of its attributes (that is, its state).
Object Identity Implementation: In RDBMS, object identity is value-based; primary key is used
to provide uniqueness. Primary keys do not provide type of object identity required in OO systems;
key only unique within a relation, not across entire system; key generally chosen from attributes
of relation, making it dependent on object state. Programming languages use variable names and
pointers/virtual memory addresses, which also compromise object identity. Advantages of OIDs:
• They are efficient. • They cannot be modified by the user.
• They are fast. • They are independent of content.
5.5.5. Methods and Messages
Method: Defines behavior of an object, as a set of encapsulated functions.
Message: Request from one object to another asking second object to execute one of its methods.
Object Showing Attributes and Methods: Example of a Method:
Method void updateSalary(Float increment)
{
Salary=Salary + Increment}
5.5.6. Classes, Subclasses, Superclasses and Inheritance
Class: Blueprint for defining a set of similar objects. Objects in a class are called instances. Objects
with similar attributes and respond to same message are grouped together. Defined only once and
used by many objects. It is collection of similar objects. Objects in a class are called instances of
the class. E.g.: Class Definition: defining the class BRANCH
BRANCH

9
Attributes
brabchNo
street
city
postcode
Methods
Print()
getPostCode()
numberofStaff()
Objects of BRANCH class

brabchNo=B005 brabchNo=B007 brabchNo=B003


street=st1 street=st2 street=st2
city=Addis city=Dire city=Bahirdar
postcode=1425 postcode=452 postcode=85
Class Instance Share Attributes and Methods.

Subclasses, Superclasses, and Inheritance: Inheritance allows one class of objects to be defined
as a special case of a more general class. Special cases are subclasses and more general cases are

10
superclasses. Process of forming a superclass is generalization; forming a subclass is
specialization. Subclass inherits all properties of its superclass and can define its own unique
properties. Subclass can redefine inherited methods. All instances of subclass are also instances of
superclass. Principle of substitutability states that instance of subclass can be used whenever
method/construct expects instance of superclass. Relationship between subclass and superclass
known as A KIND OF (AKO) relationship.
Four types of inheritance: single, multiple, repeated, and selective.
Single Inheritance

Multiple Inheritance

Repeated Inheritance

11
5.5.7. Overriding and Overloading
Overriding: Process of redefining a property within a subclass. When the method signature (name
and parameters) are the same in the superclass and the child class called overriding. Example of
Overriding Might define method in Staff class to increment salary based on commission:
method void giveCommission(float branchProfit) {
salary = salary + 0.02 * branchProfit; }
May wish to perform different calculation for commission in Manager subclass:
method void giveCommission(float branchProfit) {
salary = salary + 0.05 * branchProfit; }
Overloading: Allows name of a method to be reused with a class or across classes. When two or
more methods in the same class have the same name but different parameters called overloading.
Overloading Print Method:

12
5.5.8. Polymorphism and Dynamic Binding
Polymorphism: Means ‘many forms’. Three types: operation, inclusion, and parametric.
Dynamic Binding: Runtime process of selecting appropriate method based on an object’s type.
With list consisting of an arbitrary number of objects from the Staff hierarchy, we can write: list[i].
print. And runtime system will determine which print () method to invoke depending on the
object’s (sub)type.

5.6. Storing Objects in Relational Database Systems


One approach to achieving persistence with an OOPL is to use an RDBMS as the underlying
storage engine. Requires mapping class instances (i.e. objects) to one or more tuples distributed
over one or more relations. To handle class hierarchy, have two basics tasks to perform:
1. Design relations to represent class hierarchy;
2. Design how objects will be accessed.

5.6.1. Mapping Classes to Relations


Number of strategies for mapping classes to relations, although each results in a loss of semantic
information.
1. Map each class or subclass to a relation:
Staff (staffNo, fName, lName, position, sex, DOB, salary)
Manager (staffNo, bonus, mgrStartDate)
SalesPersonnel (staffNo, salesArea, carAllowance)

13
Secretary (staffNo, typingSpeed)
2. Map each subclass to a relation:
Manager (staffNo, fName, lName, position, sex, DOB, salary, bonus, mgrStartDate)
SalesPersonnel (staffNo, fName, lName, position, sex, DOB, salary, salesArea, carAllowance)
Secretary (staffNo, fName, lName, position, sex, DOB, salary, typingSpeed)
3. Map the hierarchy to a single relation:
Staff (staffNo, fName, lName, position, sex, DOB, salary, bonus, mgrStartDate, salesArea,
carAllowance, typingSpeed, typeFlag)
5.6.2. Storage and Access of Persistent Objects
Transient objects vs. Persistent objects
Transient objects: exist in the executing program and disappear once the program terminates.
Persistent objects: are stored in the database and persist after program termination. The typical
mechanisms for making an object persistent are naming and reachability. Approaches to make
transient objects persistent include establishing:
• Persistence by Class: declare all objects of a class to be persistent; simple but inflexible.
• Persistence by Creation extend the syntax for creating objects to specify that an object is
persistent.
• Persistence by Marking: an object that is to persist beyond program execution is marked
as persistent before program termination.
• Persistence by Reachability: declare (root) persistent objects; objects are persistent if they
are referred to (directly or indirectly) from a root object.

14

You might also like