37
Object Object Oriented DBMS Oriented DBMS Database that stores data Database that stores data elements as objects. Uses elements as objects. Uses object-oriented concepts. object-oriented concepts. The term object oriented The term object oriented is abbreviated by OO or O- is abbreviated by OO or O- O O

Objectorienteddbms Selective Inheritance

Embed Size (px)

Citation preview

Page 1: Objectorienteddbms Selective Inheritance

Object Object Oriented Oriented DBMSDBMS

Database that stores data Database that stores data elements as objects. Uses elements as objects. Uses object-oriented concepts.object-oriented concepts.The term object oriented is The term object oriented is abbreviated by OO or O-Oabbreviated by OO or O-O

Page 2: Objectorienteddbms Selective Inheritance

ObjectObject The entity that contains both attributes as

well as the actions associated with it The object has two components1. State2. behavior Attributes can be classified into simple

and complex An object is described by following

characteristicsIdentifier: a system-wide unique id for an objectName: an object may also have a unique name in DB (optional)Lifetime: determines if the object is persistent or transient

Page 3: Objectorienteddbms Selective Inheritance

A simple attribute can be an integer, string, real and so on. Which takes on specific values.

A complex attribute can contain collection and/or references.

A reference attribute represent a relationship between objects and contain a value or values.

Page 4: Objectorienteddbms Selective Inheritance

ExampleExample

Object attributes for branch instance

Attribute ValuesBranchNo B003 simpleStreet 163 main stCity IslamabadPostcode 22010SalesStaff Ali khan; Atif khan

c/r Manager Amjad khan

Page 5: Objectorienteddbms Selective Inheritance

BranchNo is example of simple attribute with value B003

The attribute Salesstaff is collection of staff objects.

Salestaff is example of reference attribute.

The reference attribute is similar to foreign key in the relational DBMS.

Page 6: Objectorienteddbms Selective Inheritance

Features of OOFeatures of OO1.1.Object IdentityObject Identity

An OO database provides a unique identity to each independent object stored in the database.

This unique identity is implemented via a unique system generated object identifier OID.

The value of OID is not visible to the user but it is used internally by the system to identify each object uniquely.

Page 7: Objectorienteddbms Selective Inheritance

The main property required of an OID is that it be immutable that is the OID value of a particular object should not change.

It is also desirable that each OID be used only once, that is even the object is removed from the database its OID should not be assigned to another object.

OID cannot be modified by the user.

Page 8: Objectorienteddbms Selective Inheritance

2.Abstraction2.Abstraction

Abstraction is the process of identifying the essential aspects of an entity and ignoring the unimportant properties.

There are two fundamental aspects of abstraction

1. Encapsulation2. Information hiding

Page 9: Objectorienteddbms Selective Inheritance

EncapsulationEncapsulation The concept of encapsulation means that an

object contains both data structure and the set of operations that can be used to manipulate it.

ExampleDefine class Employee: type tuple( name: string; birthdate: date; salary: float; ); operations create-emp: employee; destroy-emp: boolean;End employee;

Page 10: Objectorienteddbms Selective Inheritance

Information hidingInformation hiding

The concept of information hiding is that we separate the external aspects of an object from its internal details.

The internal details are hidden from the user.

So that the internal details can be changed without affecting the application that use it, that is the external details remain the same.

User only knows available methods and how to call them.

Page 11: Objectorienteddbms Selective Inheritance

3.Methods and 3.Methods and MessagesMessages In object technology functions are

usually called methods. Methods define the behavior of the

object. They can be used to change the

object’s state by modifying its attribute values

A method consist of a name and a body that perform the action associated with method name

Page 12: Objectorienteddbms Selective Inheritance

ExampleExamplemethod void updatesalary(float

increment){Salary=salary+increment}It is a method use to update a member

of staff’s salary.

MessagesMessagesMessages are the means by which

objects

Page 13: Objectorienteddbms Selective Inheritance

communicate. A message is simply a request from one object to another asking the object to execute one of its methods.

ExampleStaffobject.updatesalary(100)4.Classes4.ClassesClasses are used to define a set

of similar objects. Objects having same attributes

and respond to same messages can be grouped together to form a class.

Page 14: Objectorienteddbms Selective Inheritance

ExampleExample class

BRANCH

attributes

branchno city postcode

methods

print() getpostcode()

Branchno=b003City=london

Postcode=78jj

Branchno=b005City=london

Postcode=09jik

Page 15: Objectorienteddbms Selective Inheritance

Subclasses, Subclasses, SuperclassesSuperclassesand inheritanceand inheritanceSome objects may have similar but not identical attributes and methods. If there is a large degree of similarity, it would be useful to be able to share the common properties.Inheritance allows one class to be defined as a special case of a more general class.These special cases are known as subclasses and the more general cases are known as superclasses.

Page 16: Objectorienteddbms Selective Inheritance

There are several forms of inheritance

1. Single inheritance2. Multiple inheritance3. Repeated inheritance4. Selective inheritance Single inheritance:Single inheritance:Single inheritance refers to the

fact that the subclasses inherit from no more than one superclass.

Page 17: Objectorienteddbms Selective Inheritance

ExampleExample

person

staff

manager SalesStaff

Superclasses

subclasses

Staff is also a subclassOf a superclass person

Page 18: Objectorienteddbms Selective Inheritance

Multiple inheritanceMultiple inheritance Multiple inheritance refer that

the subclass inherit from more than one superclasses.

Example:Example:manager SalesStaff

salesmanager

Page 19: Objectorienteddbms Selective Inheritance

The multiple inheritance is very problematic . The conflict arises when the superclasses contain the same attributes or method.

It can be handled by the following ways:

Include both attributes/method and use the name of the superclass as qualifier

For example if bonus is attribute of both manager and SalesStaff the subclass salesmanager can inherit bonus from both, and qualify bonus in salesmanager as either manager.bonus or SalesStaff.bonus

Page 20: Objectorienteddbms Selective Inheritance

Use single inheritance to avoid conflict

For example Salesmanager manager

salesstaffOr

Salesmanager salesstaff manager

Repeated inheritanceRepeated inheritanceIt is a special case of multiple inheritance

in which the superclasses inherit from a common superclass.

The inheritance mechanism must ensure that the subclass does not inherit properties from the superclass twice.

Page 21: Objectorienteddbms Selective Inheritance

The multiple inheritance is very problematic . The conflict arises when the superclasses contain the same attributes or method.

It can be handled by the following ways:

Include both attributes/method and use the name of the superclass as qualifier

For example if bonus is attribute of both manager and SalesStaff the subclass salesmanager can inherit bonus from both, and qualify bonus in salesmanager as either manager.bonus or SalesStaff.bonus

Page 22: Objectorienteddbms Selective Inheritance

ExampleExample

staff

manager salesstaff

salesmanager

Page 23: Objectorienteddbms Selective Inheritance

Selective inheritanceSelective inheritance It allows a subclass to inherit a

limited number of properties from the superclass.

Overriding and Overriding and overloadingoverloading

Properties are automatically inherited by subclasses from their superclasses.

However it is possible to redefine a property in the subclass. This process is called overriding.

Page 24: Objectorienteddbms Selective Inheritance

For example we might define a method in the staff class to increment salary

Method void givecommission(float profit){Salary=salary+0.02*profit;}However we may wish to perform a

different calculation for commission in manager subclass, we can do this by redefing the overriding

Method void givecommission(float profit){salary=salary+0.05*profit;}

Page 25: Objectorienteddbms Selective Inheritance

OverloadingOverloading Overloading allows the name of a

method to be reused within a class definition.

This means that a single message can perform different functions depending on which object receive it.

For example:Overloading print method for

branch object and staff object

Page 26: Objectorienteddbms Selective Inheritance

Method void print(){Printf(“branchno%s”,branchno);Printf(“city %s”,city);Printf(“postcode%s”,postcode);}

method void print(){Printf(“staffno%d”,staffno);Printf(“name%s”,name);Printf(“gender%c”,gender);}

Page 27: Objectorienteddbms Selective Inheritance

Storing objects in a relational database Mapping classes to relationsThere are number of strategies for

mapping classes to a relation but each result in a loss of semantic information.

Map each class to a relationOne approach is to map each class to a

relation.With this approach we loss the semantic

information of which class is superclass and which one is subclass.

Page 28: Objectorienteddbms Selective Inheritance

Staff

StaffnoName

PositionDob

salary

Manager

Bonusmgrstartdate

Salesperson

Salesareacarallowance

Secretary

typingspeed

Page 29: Objectorienteddbms Selective Inheritance

Staff(staffno,name,position,dob,salary)

Manager(staffno,bonus,mgrstartdate)Salesperson(staffno,salesarea,carallo

wence)Secretary(staffno,typingspeed) Map each subclass to a relationA second approach is to map each

subclass to a relation.In this approach we lost semantic

information , it is no longer clear that the relations are subclasses.

Page 30: Objectorienteddbms Selective Inheritance

Manager(staffno,name,dob,position,salary,bonus,mgrstartdate)

Salesperson(staffno,name,dob,position,salary,salesarea,carallowence)

Secretary(staffno,name,dob,position,salary,typingspeed)

Map the hierarchy to a single relation

The third approach is to map the entire hierarchy to a relation.

Again we lost some semantic information and it will produce an unwanted number of nulls for attributes that do not apply to the tuple.

Page 31: Objectorienteddbms Selective Inheritance

Staff(staffno,name,dob,position,salary,bonus,mgrstartdate,salesarea,carallowence,typingspeed)

For example for a manager tuple the attributes like salesarea,carallowence,typingspeed will be null.

Built-in interfaces for collection objects

Any collection of object inherits the basic collection interfaces such as:

Page 32: Objectorienteddbms Selective Inheritance

o.cardinality() operation returns the number of elements in the collection.

o.empty() returns true if the collection is empty

O.insert-element(e) and o.remove-element(e) insert or remove an element “e” from the collection o

Automatic (user-defined) objects

These are specified using keyword class in ODL.

Page 33: Objectorienteddbms Selective Inheritance

Class employee{attribute string name;attribute date

birthdate;attribute enum gender{M,F}

gender;relationship department work-

for

Void reassign(in string new-dname);};

Page 34: Objectorienteddbms Selective Inheritance

Object definition language (ODL) The ODL is designed to create an

object database schema.Class Class

inheritance

relationships 1.1

1:N

M:N

Page 35: Objectorienteddbms Selective Inheritance

person

faculty student

gradstudent

department

courses

section

Has faculty

Works in

advises

advisor

studentsHas section

offers

Registered in

Page 36: Objectorienteddbms Selective Inheritance

Architecture

Client—ServerMany commercial OODBMS based on the

client—server architecture.However not a system uses same client—

server model, we can distinguish three basic architecture for a client—server.

Page serverIn this approach most of the database

processing is performed by the client.

Page 37: Objectorienteddbms Selective Inheritance

The server is responsible for providing pages at the client’s request.

Database serverIn this approach most of the database

processing is performed by the server. The client simply passes request to the server.

Object serverThis approach attempts to distribute the

processing between the two components. The server is responsible to managing locks, recovery, r=enforcing security and integrity. The client is responsible for transaction management .