0% found this document useful (0 votes)
41 views26 pages

ADB Chapter6

data structures

Uploaded by

abenezer012000
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)
41 views26 pages

ADB Chapter6

data structures

Uploaded by

abenezer012000
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/ 26

Chapter Six

Object Oriented Database

1
Introduction to Object-Oriented Concepts
• Today OO concepts are applied in the areas of
databases, software engineering, knowledge bases,
artificial intelligence, and computer systems in general.
• An object typically has two components: state (value)
and behavior (operations).
• It can have a complex data structure as well as specific
operations defined by the programmer

2
Cont’d
• Objects in an OOPL exist only during program
execution are called transient objects.
• An OO database can extend the existence of objects so
that they are stored permanently in a database, and
• Hence the objects become persistent objects that exist
beyond program termination and can be retrieved later
and shared by other programs.

3
Cont’d
• OO databases store persistent objects permanently in secondary storage and

allow the sharing of these objects among multiple programs and

applications.

• An OO database system will typically interface with one or more OO

programming languages to provide persistent and shared object

capabilities.

• An object in OOPLs includes the specification of instance variables,

which hold the values that define the internal state of the object.

• An instance variable is similar to the concept of an attribute in the

relational model,
4
Cont’d
• What is Object Oriented Database (OODB)?
• A database system that incorporates all the important
object-oriented concepts
• Object oriented database enable to represent data in the
form of object
• Database systems that were based on the object data
model were known originally as object-oriented
databases (OODBs)

5
6
Object Identity
• One goal of an ODB is to maintain a direct correspondence between
real-world and database objects

• a unique identity is assigned to each independent object stored in the


database.

• This unique identity is typically implemented via a unique, system-


generated object identifier (OID).

• The main property required of an OID is that it be immutable; that


is, the OID value of a particular object should not change

7
Cont’d
• 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.
• Hence, an ODMS must have some mechanism for
generating OIDs and preserving the immutability
property
Object oriented Feature

 User defined Type and complex data type

 Encapsulation

 Inheritance

 Polymorphism

9
User-Defined Types and Complex t data ype
• To allow the creation of complex-structured objects and to
separate the declaration of a class/type from the creation of a
table

• The user will create the UDTs for a particular application as part
of the database schema.

• A UDT may be specified in its simplest form using the following


syntax:

CREATE TYPE TYPE_NAME AS (<component declarations>);

10
Cont’d
CREATE TYPE STREET_ADDR_TYPE AS (
NUMBER VARCHAR (5),
STREET NAME VARCHAR (25),
);
CREATE TYPE USA_ADDR_TYPE AS (
STREET_ADDR STREET_ADDR_TYPE,
CITY VARCHAR (25),
ZIP VARCHAR (10)
);
CREATE TYPE USA_PHONE_TYPE AS (
PHONE_TYPE VARCHAR (5),
AREA_CODE CHAR (3),
PHONE_NUM CHAR (7)
);

11
Cont’d
CREATE TYPE PERSON_TYPE AS (
NAME VARCHAR (35),
SEX CHAR,
BIRTH_DATE DATE,
PHONES USA_PHONE_TYPE ARRAY [4],
ADDR USA_ADDR_TYPE
INSTANTIABLE
NOT FINAL
REF IS SYSTEM GENERATED
INSTANCE METHOD AGE() RETURNS;
CREATE INSTANCE METHOD AGE() RETURNS INTEGER
FOR PERSON_TYPE
BEGIN
RETURN /* CODE TO CALCULATE A PERSON’S AGE FROM
TODAY’S DATE AND SELF.BIRTH_DATE */
END;
);

12
Cont’d
Object Identifiers Using Reference Types
• Unique system-generated object identifiers can be
created via the reference type using the keyword REF.
REF IS SYSTEM GENERATED
• Indicates that whenever a new PERSON_TYPE object
is created, the system will assign it a unique system-
generated identifier

13
Cont’d
• In general, the user can specify that system-generated object
identifiers for the individual rows in a table should be created.
• By using the syntax:
REF IS <OID_ATTRIBUTE>
<VALUE_GENERATION_METHOD> ;
• the user declares that the attribute named <OID_ATTRIBUTE> will
be used to identify individual tuples in the table.
• The options for <VALUE_GENERATION_METHOD> are
SYSTEM GENERATED or DERIVED.

14
Cont’d
Creating Tables Based on the UDTs

• For each UDT that is specified to be instantiable via the


phrase INSTANTIABLE, one or more tables may be created.

• where we create a table PERSON based on the


PERSON_TYPE UDT

CREATE TABLE PERSON OF PERSON_TYPE

REF IS PERSON_ID SYSTEM GENERATED;

15
Inheritance
• Inheritance allows the definition of new types based on
other predefined types, leading to a type (or class)
hierarchy.
• A type is defined by assigning it a type name and then
defining a number of attributes (instance variables) and
operations (methods) for the type.
– A subclass inherits the attributes, operations, and association
of its superclasses
Cont’d
• Sharing of data within hierarchy scope, supports code
reusability
• Student class inherits attributes and operations of Person

17
Structured Types and Inheritance in SQL
• Structured types (a.k.a. user-defined types) can be declared and used in SQL

create type Name as


(firstname varchar(20),
lastname varchar(20))
final

create type Address as


(street varchar(20),
city varchar(20),
zipcode varchar(20))

not final

– Note: final and not final indicate whether subtypes can be created
Cont’d
• Structured types can be used to create tables with composite attributes

create table person (

name Name,

address Address,

dateOfBirth date)

• Dot notation used to reference components: name.firstname

19
Type Inheritance
• Suppose that we have the following type definition for person:
create type Person
(name varchar(20),
address varchar(20))
 Using inheritance to define the student and teacher types
create type Student
under Person
(degree varchar(20),
department varchar(20))
create type Teacher
under Person
(salary integer,
department varchar(20))
 Subtypes can redefine methods by using overriding method in place of
method in the method declaration
Encapsulation of Operations
• The concept of encapsulation is one of the main characteristics
of OO languages and systems.

• It is also related to the concepts of abstract data types and


information hiding in programming languages.

• In traditional database models and systems this concept was not


applied, since it is customar to make the structure of database
objects visible to users and external programs.
Cont’d

• In object oriented database model, the implementation


of operations and object structure is hidden
• The external users of the object are only made aware of
the interface of the operations, which defines the
name and arguments (parameters) of each operation.
• The implementation is hidden from the external users;
• It includes the definition of any hidden internal data
structures of the object and the implementation of the
operations that access these structures.

22
Polymorphism
• Another characteristic of OO systems in general is that they
provide for polymorphism of operations, which is also
known as operator overloading.
• This concept allows the same operator name or symbol to be
bound to two or more different implementations of the
operator,
• Overloading
– The name of a method to be reused within a class definition or
across class definitions
• Overriding
– The name of property to be redefined in a subclass
Relational model vs Object –oriented model

Relational model
• Clean and simple.
• Great for administrative and transactional data.
• Not as good for other kinds of complex data (e.g., multimedia,
networks, CAD).
Object-Oriented models
• Complicated, but some influential ideas from Object Oriented
• Complex data types.
• Idea: Build DBMS based on OO model.

24
Advantages of OODBS
• Designer can specify the structure of objects and their
behavior (methods)

• Better interaction with object-oriented languages such as


Java and C++

• Definition of complex and user-defined types

• Encapsulation of operations and user-defined methods

25
Object-Oriented DBMS(OODBMS
• Object-Oriented DBMS(OODBMS) are DBMS
based on an Object Oriented Data Model inspired
by OO programming languages
• OODBMS Advantages
 Can handle large collections of complex types.
Thus support for aggregation, composition,
 Expressive data relationships
 Version control for evolving classes and
 Efficiently handles many-to-many relationships

26

You might also like