Chapter 5 2013 5
Chapter 5 2013 5
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.
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.
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.
4
Class hierarchy E-R diagram
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.
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:
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
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.
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