ADB Chapter6
ADB Chapter6
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
applications.
capabilities.
which hold the values that define the internal state of the object.
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
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
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.
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
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
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
name Name,
address Address,
dateOfBirth date)
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.
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)
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