0% found this document useful (0 votes)
6 views

Chapter One-Object Oriented Database Cocepts

The document provides an overview of Object-Oriented Databases (OODB), highlighting their structure, components, and advantages over traditional relational databases. It discusses key concepts such as object identity, encapsulation, inheritance, and persistence, emphasizing their importance in managing complex data structures. Additionally, it outlines the weaknesses of relational databases and the benefits of using OODBs in various applications.

Uploaded by

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

Chapter One-Object Oriented Database Cocepts

The document provides an overview of Object-Oriented Databases (OODB), highlighting their structure, components, and advantages over traditional relational databases. It discusses key concepts such as object identity, encapsulation, inheritance, and persistence, emphasizing their importance in managing complex data structures. Additionally, it outlines the weaknesses of relational databases and the benefits of using OODBs in various applications.

Uploaded by

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

HiLCoE School of Computer Science & Technology

Chapter One:
Object-Oriented Data

Advanced Database Systems


CH1-Object Oriented Database 1
Outlines 2

 Object-Oriented Concepts
 Object Identity
 Object Structure
 Type Constructors
 Encapsulation

 Methods, and Persistence


 Type Hierarchies and Inheritance
CH1-Object Oriented Database
Concepts for
Object-Oriented
Databases
Database: is a collection of data and a set of
rules used to logically organize the data by
Brain specifying certain relationships among the
storming data.

• What is database?

• Relational database ????????


• Object oriented programing language 4
Overview of Object-Oriented Concepts

• Object-Oriented Databases (OODB) are a type of database


management system that is designed to store and retrieve
data using the principles of object-oriented programming
(OOP).

• In contrast to traditional relational databases that organize


data into tables with rows and columns, object-oriented
databases model data as objects, which are instances of
classes in an object-oriented programming language.

CH1-Object Oriented Database 5


Cont. …

• Objects are self-contained units that contain both data and the operations or
methods that can be performed on that data. It helps in efficient representation
and management of complex data structures and relationships.

• Object-oriented databases are often used in applications that require the


efficient management of complex data structures and relationships, such as
CAD/CAM systems, geographic information systems, and document
management systems.

• They are also well suited for applications that require the integration of
different data types and sources, such as multimedia data or data from
multiple sources.

CH1-Object Oriented Database 6


Cont. …

CH1-Object Oriented Database 7


Weaknesses of the relational
database model
Categorized into two main areas: Data Model and Programming.
• Data Model Weaknesses:
1. A Single Bulk Data Type (Relation): The relational model
primarily uses a single data type, the relation (or table), which can
be limiting when dealing with more complex data structures.
2. No Direct Support for Hierarchies: The model lacks direct
support for hierarchical relationships, such as “part-of” or “is-a”
relationships, which are often needed to represent real-world data
more accurately.
3. No Direct Support for Advanced Data Types: It does not
natively support advanced data types like spatial data or
multimedia, which are increasingly important in modern
8
applications.
Weaknesses of the relational
database …
• Programming Weaknesses:
1. Impedance Mismatch Due to Query Language Emphasis:
There is often a mismatch between the relational query
language (SQL) and the programming languages used to
develop applications. This can make it challenging to
integrate and manipulate data seamlessly.

9
Cont’d…

2. Challenging to Make Existing Application Data


Persist: Ensuring that data from existing applications
is stored and managed persistently within a relational
database can be difficult, particularly when dealing
with complex or non-relational data structures.
• Addressing these issues often requires additional
tools, techniques, or alternative database models
that can better accommodate these needs.
Relational database Vs Object oriented
database
• Relational databases and object orientation are not
entirely compatible.
• They represent two different views of the world
Cont’d…
In RDBMs In Object oriented
Database
 all you see is data
 Stores data in Entities,  all you see is behavior
defined as tables hold  Stores data as Objects.
specific information.
 Handles comparatively  Handles larger and complex data than
simpler data. RDBMS.
 Entity type refers to the  Class describes a group of objects that
collection of entity that share have common relationships,
a common definition. behaviors, and also have similar
 RDBMS stores only data. properties.
 Data Independence from  Stores data as well as methods to use
application program it.
 A Primary key distinctively  Data Encapsulation.
identifies an object in a table..  An object identifier (OID) is an
unambiguous, long-term name for any
type of object or entity.
Cont’d…
• 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.
Components of Object-Oriented Database Model

• The main components of an object-oriented database model are:

Objects

• Objects represent real-world entities by combining data with related


operations.

• For example, an object could contain a customer’s name, address, and


account balance data along with methods to modify or retrieve that data.

• Objects enable encapsulation of both state through data attributes and


behavior through methods. This provides a cohesive and modular approach
to structure data.

CH1-Object Oriented Database 14


Cont. …
Classes
• Classes act as templates or blueprints for creating objects with
the same kinds of data and behaviors. A class defines the
structure for its instances what attributes or data members the
object will contain as well as what methods or functions it will
have.

• Classes allow for organization of objects that share similar


properties and behaviors. This promotes reusability and
maintainability in database design.
CH1-Object Oriented Database 15
Cont. …

Inheritance

• Inheritance allows classes to inherit attributes and methods


from parent classes. This enables code reuse and the creation
of specialized child classes.

• The class hierarchy represents these parent-child


relationships. A base or superclass provides common data and
behaviors shared by derived subclasses down the hierarchy.
Subclasses can override or extend parent functionality.

CH1-Object Oriented Database 16


Cont. …

Methods

• Methods are functions defined within a class that


represent the behaviors or actions that objects created
from that class can perform.

• Methods operate on the object’s data members and


encapsulate the logic for manipulating the object’s state.
This provides an organized approach to implementing
functionality for the class.
CH1-Object Oriented Database 17
Cont. …

Attributes

• Attributes are data members that hold the state or


properties of an object instantiated from a class. They
define the characteristics of those objects.

• Attributes store descriptive information about the object


that can be of various data types like strings, numbers,
etc. This allows representation of diverse properties.

CH1-Object Oriented Database 18


Cont. …

Encapsulation

• Encapsulation binds together the data attributes and the


methods that manipulate them within a class. Certain
components may be hidden or restricted from direct access
externally to protect data integrity.

• Interaction is only through defined interfaces. This guards


against misuse while enabling specialized implementation
details.
CH1-Object Oriented Database 19
Cont. …

CH1-Object Oriented Database 20


Cont. …

Polymorphism

• Polymorphism allows objects of different classes to be


treated as objects of a common superclass type and used
interchangeably.

• A single method interface can work across multiple data


types.

• Polymorphism provides flexibility to extend systems and


write more generic reusable code.
CH1-Object Oriented Database 21
Cont. …
Persistence

• Persistence refers to objects continuing to exist even after the


program that created them ends. Their state is saved so objects can
be retrieved in subsequent sessions. This is crucial for storing data
long-term without loss of information between interactions.

Identity

• Every object is assigned a unique identifier that distinguishes it


from other objects even if they have identical attribute values. This
allows precise management of object references and relationships.
CH1-Object Oriented Database 22
Cont. …

Transactions

• Transactions group operations into an all-or-nothing


unit. If any part fails, the entire transaction is rolled
back to maintain database consistency.

• Transactions provide reliability with features like


atomicity, isolation, and durability that ensure
integrity.
CH1-Object Oriented Database 23
Cont. …

CH1-Object Oriented Database 24


Advantages of Object-Oriented Databases

Efficient representation of complex data structures:


One of the main advantages of object-oriented
databases is that they allow for the efficient
representation and management of complex data
structures and relationships.

• This is particularly useful for applications that require


the integration of different data types and sources, such
as multimedia data or data from multiple sources.
CH1-Object Oriented Database 25
Cont. …

Improved code reuse and modularity: Object-oriented


databases support inheritance and polymorphism, which allow
for the efficient reuse of code and data structures. This simplifies
the development and management of complex data structures,
and improves the modularity and maintainability of the database.
Support for data integration: Object-oriented databases are
well suited for applications that require the integration of
different data types and sources, since they support the
representation of complex data structures and relationships.

CH1-Object Oriented Database 26


Cont. …

Flexibility and adaptability: Object-oriented databases are


highly flexible and adaptable, which means that they can easily
handle changes in data structures and requirements. This is
particularly useful for applications that require the ability to
quickly adapt to changing business needs and requirements.
Improved performance: Object-oriented databases can have
improved performance compared to other database models, since
they are optimized for the efficient representation and
manipulation of complex data structures and relationships.
CH1-Object Oriented Database 27
Disadvantages of Object-Oriented Databases

Complexity and learning curve: One of the main


disadvantages of object-oriented databases is that they
can be complex and difficult to learn and use,
especially for developers who are not familiar with
object-oriented programming (OOP).

• This can increase the time and resources required to


develop and maintain applications that use an object-
oriented database.
CH1-Object Oriented Database 28
Cont. …
Limited support for SQL: Object-oriented databases do not support
SQL, which is the standardized and widely used language for managing
and querying data in relational databases. This can limit their compatibility
with other systems and applications that use SQL, and may require
developers to learn and use specialized object-oriented query languages.
Limited vendor support: Object-oriented databases are not as widely
used as other database models, which means that they may have limited
vendor support and resources compared to other database models. This can
make it more difficult to find support and expertise for object-oriented
databases.

CH1-Object Oriented Database 29


Cont. …
Potential vendor lock-in: Organizations that use an
object-oriented database may be dependent on their
database vendor, which can create vendor lock-in and limit
their ability to switch to another database in the future.
Compatibility issues: Object-oriented databases may not
be compatible with other database models, which can limit
their interoperability and integration with other systems
and applications.
CH1-Object Oriented Database 30
Object Identity, Object Structure, and
Type Constructors

• In Object-Oriented Databases (OODBs), three


important concepts are:
Object Identity
Object Structure, and
Type Constructors.

• Let's explore each of these concepts:

CH1-Object Oriented Database 31


Object Identity
• Object Identity refers to the unique identifier associated with each
object in the database. It is a crucial aspect of OODBs because it allows
the system to distinguish one object from another.

• Object Identity ensures that each object is uniquely identifiable, which is


essential for maintaining data integrity and supporting relationships
between objects.

• Unlike in relational databases where primary keys are used for


identification, in OODBs, the identity is often inherent in the object
itself.

CH1-Object Oriented Database 32


Cont. …

• Here are key aspects of Object Identity in Object-Oriented Databases:

Unique Identifier: Each object within the OODB is assigned a


unique identifier, often referred to as an "object identifier" or "OID."
This identifier is used to distinguish one object from another.
Inherent Identity: Object Identity is often inherent in the object itself
and is not dependent on external factors.

• It is a key feature of the encapsulation principle in object-oriented


programming, where an object's identity is encapsulated within the
object.

CH1-Object Oriented Database 33


Cont. …
Support for Relationships: Object Identity plays a crucial role
in establishing and maintaining relationships between objects.
When one object refers to another object through attributes or
associations, it is the unique identifier that allows for accurate
referencing.
Persistence: Object Identity is maintained consistently across
different states of an object. Even if an object is stored,
retrieved, modified, and re-stored in the database, its unique
identity remains the same.
CH1-Object Oriented Database 34
Cont. …
Identity Independence: Object Identity provides identity
independence, meaning that the identity of an object is maintained
regardless of changes to its attributes or state. This is in contrast
to relational databases, where the primary key is often tied to the
data values and may change if those values change.
Object Evolution: Object Identity supports the evolution of
objects over time. As objects are updated or modified, their unique
identity allows the system to track and manage changes effectively.

CH1-Object Oriented Database 35


Object Structure

Object Structure refers to the way in which data and methods are
organized within an object. It encompasses the attributes (data) and
methods (functions) that define the behavior of the object.
The organization of data and methods within an object is
fundamental to the encapsulation principle of object-oriented
programming.

• Encapsulation ensures that an object's internal representation is


hidden from the outside world, and interaction with the object is
performed through well-defined interfaces.
CH1-Object Oriented Database 36
Cont. …
• Here are key aspects related to Object Structure in Object-Oriented
Databases:
Classes: Objects in an OODB are instances of classes. Classes define
the blueprint or template for creating objects. They specify the
attributes (data) and methods (functions) that objects of that class will
have.
Attributes: Attributes represent the data associated with an object.
Each object has a set of attributes that define its state. These attributes
can be of various data types and may include simple types (integers,
strings) or more complex types (other objects).
CH1-Object Oriented Database 37
Cont. …
Methods: Methods are functions associated with objects. They
define the behavior or operations that can be performed on objects of
a particular class. Methods encapsulate the functionality related to
the object, promoting encapsulation and modularity.
Encapsulation: Encapsulation is a key principle in object-oriented
programming and is closely tied to object structure. It involves
bundling the data (attributes) and methods that operate on the data
within a single unit (the object). Encapsulation helps in hiding the
internal details of an object and exposing only the necessary
interfaces.
CH1-Object Oriented Database 38
Cont. …
Inheritance: Inheritance is a mechanism that allows the creation
of new classes based on existing ones. It facilitates code reuse
and helps in modeling relationships between classes. Inherited
classes share the attributes and methods of their parent classes.
Relationships: Objects in an OODB can have relationships with
other objects. These relationships are defined by associations
between classes and can include one-to-one, one-to-many, or
many-to-many relationships. Object Structure involves
specifying how objects are related to each other.
CH1-Object Oriented Database 39
Cont. …

• Object Structure in an Object-Oriented Database


encompasses the organization of objects through classes,
the definition of attributes and methods within those
classes, encapsulation of data and functionality, inheritance
for code reuse, and the specification of relationships
between objects. This structure is fundamental to the
principles of object-oriented programming and plays a
crucial role in designing and managing data in an OODB.
CH1-Object Oriented Database 40
Type Constructors
Type Constructors are mechanisms in OODBs that define and
create types or classes. They specify how objects of a particular
type should be constructed, including their attributes and methods.

Type Constructors play a crucial role in the schema definition of


the database. They define the blueprint for creating objects, ensuring
consistency and structure across instances of the same type.

• Type Constructors support features such as inheritance, allowing for


the creation of new types based on existing ones.

CH1-Object Oriented Database 41


Cont. …
• Here's a breakdown of the significance and features of Type
Constructors in OODBs:
Type Definition: Type Constructors play a crucial role in the
definition of types or classes within an OODB. They provide a
means to specify the structure of objects, including attributes and
methods.

• Example: In an OODB, a Type Constructor might be used to


define a "Person" class with attributes such as name, age, and
address.
CH1-Object Oriented Database 42
Cont. …

Attribute Specification: Type Constructors allow


the specification of attributes associated with a
class. Attributes represent the data members or
properties of an object.

• Example: For the "Person" class, a Type


Constructor would specify attributes like "name"
(string), "age" (integer), and "address" (string).
CH1-Object Oriented Database 43
Cont. …
Method Declaration: Type Constructors can include the declaration of
methods that define the behavior of objects belonging to a particular
class.

• Example: For the "Person" class, a Type Constructor might declare


methods like "getAge()" or "updateAddress()".
Inheritance Support: Type Constructors often support the concept of
inheritance, allowing the creation of new classes based on existing ones.
This promotes code reuse and hierarchical structuring of classes.

• Example: A Type Constructor could enable the creation of a "Student"


class that inherits attributes and methods from the "Person" class.

CH1-Object Oriented Database 44


Cont. …
Encapsulation and Access Control: Type Constructors
contribute to encapsulation, a fundamental principle of
object-oriented programming. They define the visibility
and accessibility of attributes and methods, supporting
the concept of private and public members.

• Example: A Type Constructor might specify that the


"age" attribute is private, accessible only through getter
and setter methods.
CH1-Object Oriented Database 45
Cont. …
Polymorphism: Some Type Constructors support
polymorphism, allowing objects of different classes to be
treated as objects of a common base class. This enhances
flexibility and enables more generic code.

• Example: A Type Constructor might support


polymorphic behavior by allowing objects of various
derived classes to be treated uniformly through a
common interface.
CH1-Object Oriented Database 46
Cont. …

• Type Constructors in Object-Oriented Databases are


essential for defining the structure, behavior, and
relationships of objects within the database. They
provide a means for creating and organizing types or
classes, facilitating the modeling of real-world entities
and their interactions. The specific features and syntax
of Type Constructors may vary depending on the OODB
system being used.
CH1-Object Oriented Database 47
Type Constructors (1)

 In ODBs, a complex type may be


constructed from other types by nesting
of type constructors.
 The three most basic constructors are
 Atom
 struct (or tuple) and
 Collection
Type Constructors (2)
 Atom Constructor:
 Used to represent all basic atomic values,
such as integers, real numbers, character
strings, Booleans, and any other basic
data types that the system supports
directly.
 These basic data types are called single-
valued or atomic types, since each value
of the type is considered an atomic
(indivisible) single value.
Type Constructors (3)
 Struct (or tuple) constructor:
 create standard structured types, such as
the tuples (record types) in the basic
relational model.
 A structured type is made up of several
components and is also sometimes
referred to as a compound or composite
type.
 Itis type generator, because many
different structured types can be created.
Type Constructors (3)…

 For example, two different structured


types that can be created are:
struct Name<FirstName: string,
MiddleInitial: char, LastName: string>,
and
struct CollegeDegree<Major: string,
Degree: string, Year: date>.
Type Constructors (4)
 Collection (Multivalued) Constructor:
 include the set(T), list(T), bag(T), array(T), and
dictionary(K,T) type constructors.
 These allow part of an object or literal value to
include a collection of other objects or values
when needed.
 Considered to be type generators because many
different types can be created.
 For example, set(string), set(integer), and
set(Employee) are three different types that can be
created from the set type constructor.
Type Constructors (5)
Object Identity, Object Structure,
and Type Constructors Examples
(1)
 Example 1

 One possible relational database state corresponding to


COMPANY schema
Object Identity, Object Structure,
and Type Constructors Examples
(2)
 Example 1 (contd.):
Object Identity, Object Structure,
and Type Constructors Examples
(3)
 Example 1 (contd.)
Object Identity, Object Structure,
and Type Constructors Examples
(4)
 Example 1 (contd.)
 We use i1, i2, i3, . . . to stand for unique system-
generated object identifiers. Consider the
following objects:
o = (i1, atom, ‘Houston’)
1
o = (i2, atom, ‘Bellaire’)
2
o = (i3, atom, ‘Sugarland’)
3
o = (i4, atom, 5)
4
o = (i5, atom, ‘Research’)
5
o = (i6, atom, ‘1988-05-22’)
6
o = (i7, set, {i1, i2, i3})
7
Object Identity, Object Structure,
and Type Constructors Examples
(5)
 Example 1(contd.)
o8 = (i8, tuple, <dname:i5, dnumber:i4, mgr:i9,
locations:i7, employees:i10, projects:i11>)
o9= (i9, tuple, <manager:i1,
manager_start_date:i6>)
o10 = (i10, set, {i12, i13, i14})
o11 = (i11, set {i15, i16, i17})
o12= (i12, tuple, <fname:i18, minit:i19, lname:i20,
ssn:i21, . . ., salary:i26, supervi­sor:i27, dept:i8>)
. ..
Object Identity, Object Structure,
and Type Constructors Examples
(6)
 Example 1 (contd.)
 The first six objects listed in this example
represent atomic values.
 Object seven is a set-valued object that
represents the set of locations for
department 5; the set refers to the atomic
objects with values {‘Houston’, ‘Bellaire’,
‘Sugarland’}.
 Object 8 is a tuple-valued object that
represents department 5 itself, and has the
attributes DNAME, DNUMBER, MGR,
LOCATIONS, and so on.
Object Identity, Object Structure,
and Type Constructors Examples
(7)
 Example 2:
 This example illustrates the difference
between the two definitions for
comparing object states for equality.
 o1 = (i1, tuple, <a1:i4, a2:i6>)
 o2 = (i2, tuple, <a1:i5, a2:i6>)
 o3 = (i3, tuple, <a1:i4, a2:i6>)
 o4 = (i4, atom, 10)
 o5 = (i5, atom, 10)
 o = (i , atom, 20)
Object Identity, Object Structure,
and Type Constructors Examples
(8)
 Example 2 (contd.):
 In this example, The objects o1 and o2 have
equal states, since their states at the atomic
level are the same but the values are reached
through distinct objects o4 and o5.
 However, the states of objects o1 and o3 are
identical, even though the objects themselves
are not because they have distinct OIDs.
 Similarly, although the states of o4 and o5 are
identical, the actual objects o4 and o5 are
equal but not identical, because they have
distinct OIDs.
Identity

• One goal of an ODMS (Object Data Management


System) is to maintain a direct correspondence between
real-world and database objects so that objects do not
lose their integrity and identity and can easily be
identified and operated upon.
• Hence, an ODMS provides a unique identity to each
independent object stored in the database. This unique
identity is typically implemented via a unique, system-
generated object identifier (OID).
• The value of an OID is not visible to the external user,
but is used internally by the system to identify each
object uniquely and to create and manage inter-object
references.
6
2
…continued

• 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.
Structure
• Another feature of an ODMS (and ODBs in
general) is that objects and literals may
have a type structure of arbitrary
complexity in order to contain all of the
necessary information that describes the
object or literal. 6
3
Cont’d…
• In ODBs, a complex type may be constructed
from other types by nesting of type
constructors.
• The three most basic constructors are atom,
struct (or tuple), and collection.

6
4
Cont’d…

1. One type constructor has been called the atom


constructor
– This includes the basic built-in data types of the object
model, integers, strings, floating point numbers,
enumerated types, Booleans, and so on.
2. A second type constructor is referred to as the struct
(or tuple) constructor.
– A structured type is made up of several components,
and is also sometimes referred to as a compound or
composite type.
Cont’d…

3. Collection (or multivalued) type constructors


include the set(T), list(T), bag(T), array(T), and
dictionary(K,T) type constructors.
These allow part of an object or literal value to
include a collection of other objects or values
when needed.

6
6
…continued
• The set constructor will create objects or
literals that are a set of distinct elements
{i1,i2,...,in},all of the same type.
• The bag constructor (sometimes called a
multiset) is similar to a set except that the
elements in a bag need not be distinct.
• The list constructor will create an ordered list
[i1,i2,...,in] of OIDs or values of the same type.
• A list is similar to a bag except that the
elements in a list are ordered

6
7
• The array constructor creates a single-
dimensional array of elements of the same
type.
• The main difference between array and list is
that a list can have an arbitrary number of
elements whereas an array typically has a
maximum size.
• the dictionary constructor creates a collection
of two tuples (K, V), where the value of a key K
can be used to retrieve the corresponding
value V.
…cont
Encapsulation of Operations, Methods, and Persistence

• Encapsulation of Operations :In traditional


database models and systems this concept was
not applied, since it is customary to make the
structure of database objects visible to users
and external programs.
• The concepts of encapsulation is applied to
database objects in ODBs by defining the
behavior of a type of object based on the
operations that can be externally applied to
objects of that type.
7
0
Cont’d…
• 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.
• The interface part of an operation is sometimes called
the signature, and the operation implementation is
sometimes called the method.

7
1
Group Discussion
Discuss for 20 min and report the discussion
• E-R diagram, Normalization, UML ,Database
Design
• What is the different between oodb and relational
database?
• What does encapsulation, inheritance and
polymorphism mean?
• What is object identity (oid) mean and immutable
mean?
• What are the types of structure ?
7
2
Specifying Object Persistence via Naming
and Reachability.
• 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.

7
3
Cont’d…
• The naming mechanism involves giving an object a
unique persistent name within a particular database.
• This persistent object name can be given via a specific
statement or operation in the program.
• The named persistent objects are used as entry points to
the database through which users and applications can
start their database access.
• The reachability mechanism works by making the object
reachable from some other persistent object. An object B
is said to be reachable from an object A if a sequence of
references in the database lead from object A to object B.

7
4
Type Hierarchies and Inheritance
• Another main characteristic of ODBs is that they allow type
hierarchies and inheritance.
• We use a simple OO model in this section a model in which
attributes and operations are treated uniformly since both
attributes and operations can be inherited.
• Inheritance allows the definition of new types based on other
predefined types, leading to a type (or class) hierarchy.

7
6
Cont’d…

• two types of inheritance relationships exist: behavior only


inheritance and state plus behavior inheritance (Extend).
• Behavior inheritance is also known as ISA or interface
inheritance, and is specified by the colon (:) notation.
• Hence, in the ODMG(Object Data Management Group )
object model, behavior inheritance requires the super type to
be an interface, whereas the subtype could be either a class or
another interface.
IsA
Properties of IsA
– Inheritance - All attributes of the supertype apply to the
subtype.
• E.g., GPA attribute of Student applies to Freshman
• The subtype inherits all attributes of its supertype.
• The key of the supertype is also the key of the subtype
– Transitivity - This property creates a hierarchy of IsA
relationships
• Student is subtype of Person,
Freshman is subtype of Student,
therefore Freshman is also a subtype of Person
…continued
• The other inheritance relationship, called EXTENDS
inheritance, is specified by the keyword extends. It is used
to inherit both state and behavior strictly among classes, so
both the super type and the subtype must be classes.
• Multiple inheritance via extends is not permitted.
However, multiple inheritance is allowed for behavior
inheritance via the colon (:) notation.

8
0
…continued
• A type in its simplest form has a type name and a
list of visible (public) functions. When specifying
a type in this section, we use the following format,
which does not specify arguments of functions, to
simplify the discussion:
TYPE_NAME: function, function, ..., function
• For example, a type that describes characteristics
of a PERSON may be defined as follows:
PERSON: Name, Address, Birth_date, Age, Ssn

8
1
…continued
• The concept of subtype is useful when the designer or user must
create a new type that is similar but not identical to an already
defined type. The subtype then inherits all the functions of the
predefined type, which is referred to as the supertype.
• For example, suppose that we want to define two new types
EMPLOYEE and STUDENT as follows:
EMPLOYEE: Name, Address, Birth_date, Age, Ssn, Salary,
Hire_date, Seniority
STUDENT: Name, Address, Birth_date, Age, Ssn, Major, Gpa
• Since both STUDENT and EMPLOYEE include all the
functions defined for PERSON plus some additional functions
of their own, we can declare them to be subtypes of PERSON.
8
2
…continued

• Therefore, we can declare EMPLOYEE and


STUDENT as follows: EMPLOYEE subtype-of
PERSON: Salary, Hire_date, Seniority
STUDENT subtype-of PERSON: Major, Gpa
• In general, a subtype includes all of the
functions that are defined for its supertype plus
some additional functions that are specific only
to the subtype.

8
3
Multiple Inheritance and Selective Inheritance

• Multiple inheritance occurs when a certain subtype


T is a subtype of two (or more) types and hence
inherits the functions (attributes and methods) of
both supertypes.
• For example, we may create a subtype
ENGINEERING_MANAGER that is a subtype of
both MANAGER and ENGINEER. This leads to the
creation of a type lattice rather than a type hierarchy.

8
4
…continued
• One problem that can occur with multiple inheritance is that the
supertypes from which the subtype inherits may have distinct
functions of the same name, creating an ambiguity.
• For example, both MANAGER and ENGINEER may have a
function called Salary. If the Salary function is implemented by
different methods in the MANAGER and ENGINEER supertypes,
an ambiguity exists as to which of the two is inherited by the
subtype ENGINEERING_MANAGER.

8
5
Cont’d…

• It is possible,however, that both ENGINEER and


MANAGER inherit Salary from the same
supertype (such as EMPLOYEE) higher up in the
lattice.
• The general rule is that if a function is inherited
from some common supertype, then it is inherited
only once.
• In such a case, there is no ambiguity; the problem
only arises if the functions are distinct in the two
supertypes.
Cont’d…
• One solution is to have the system check for
ambiguity when the subtype is created, and to let the
user explicitly choose which function is to be
inherited at this time.
• A second solution is to use some system default.
• A third solution is to disallow multiple inheritance
altogether if name ambiguity occurs, instead forcing
the user to change the name of one of the functions in
one of the supertypes.

8
7
Cont’d…
• Selective inheritance occurs when a subtype
inherits only some of the functions of a
supertype.
• Other functions are not inherited. In this case,
an EXCEPT clause may be used to list the
functions in a supertype that are not to be
inherited by the subtype.

8
8
Polymorphism of Operations (Operator
Overloading).
• This concept allows the same operator name or symbol to
be bound to two or more different implementations of the
operator, depending on the type of objects to which the
operator is applied.
• example, the function Area is declared for all objects of type
GEOMETRY_OBJECT. However, the implementation of the
method for Area may differ for each subtype of
GEOMETRY_OBJECT. One possibility is to have a general
implementation for calculating the area of a generalized
GEOMETRY_OBJECT

8
9
Cont’d…

• (for example, by writing a general algorithm to


calculate the area of a polygon) and then to rewrite
more efficient algorithms to calculate the areas of
specific types of geo-metric objects, such as a circle,
a rectangle, a triangle, and so on.
• In this case, the Area function is overloaded by
different implementations.
Revision Points
• What is the difference between transient object and
persistent object?
• How to specify persistent object?
• What is hierarchy and inheritance?
• What are the types of inheritance?
• What is the difference between multiple and selective
inheritance?
• What are the problems of multiple inheritance and
describe the solution?
9
1
End of Chapter 1

You might also like