Sei sulla pagina 1di 14

CHAPTER FIVE

5. Object Oriented Database Management Systems(OODBMS)


Learning Objectives: This chapter provides an overview of object oriented database management
system. The need for object oriented concepts in DBMS, and OODBMS are discussed elaborately
in this chapter. After completing this chapter the reader should be familiar with the following
concepts:
 Object Oriented Concepts
 Drawbacks of relational DBMS
 OODBMS definitions
 OO Database Design and Implementation
 OO Data modeling and E-R diagramming
 Storing objects in relational database systems

5.1. Object Orientation


Object Orientation: Set of design and development principles. Based on autonomous computer
structures known as objects. OO Contribution areas:
• Programming Languages
• Graphical User Interfaces
• Databases
• Design
• Operating Systems
5.1.1. Evolution of OO Concepts
Concepts stem from object-oriented programming languages (OOPLs) such as Ada, ALGOL,
LISP, SIMULA...
OOPLs Goals:
• Easy-to-use development environment
• Powerful modeling tools for development
• Decrease in development time
• Make reusable code

1
5.1.2. Advanced Database Applications
The application of database is being highly practiced in complex applications demanding
different way of modeling and designing. Some of these applications are:
• Computer Aided Design (CAD) • Multimedia System
• Computer Aided Manufacturing • Digital Publication
• Computer Aided Software Engineering • Geographic Information System
• Network Management System • Interactive and Dynamic Web Sites

5.2. History 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.

5.3. Drawbacks/Weaknesses of relational DBMS


Poor Representation of “Real World” Entities: Normalization leads to relations that do not
correspond to entities in “real world”.
Semantic Overloading: Relational model is semantically overloaded. Representation of complex
relationship is difficult. E.g. M:N relationship is represented by adding one additional relation
(making the relation an entity). One cannot distinguish a relation from a relationship. Difficult to

2
distinguish different types of relationship.
Poor Support for Integrity and Enterprise Constraints: Many commercial BMS do not support
all integrity constraints. The relational model doesn’t support enterprise constraints it has to be
done on the DBMS.
Homogeneous Data Structure: Relational model assumes both horizontal and vertical
homogeneity. Horizontal Homogeneity each tuple of a relation have same number and type of
attributes. Vertical Homogeneity values of an attribute should come from same domain. Field value
should be atomic.
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.

5.4. Object Oriented Concepts


Object-oriented concepts can be used in different ways Object-orientation can be used as a design
tool, and be encoded into. For example, a relational database analogous to modeling data with E-
R diagram and then converting to a set of relations. The concepts of object orientation can be
incorporated into a programming language that is used to manipulate the database.
Object-relational systems: add complex types and object-orientation to relational language.
Persistent programming languages: extend object-oriented programming language to deal with
databases by adding concepts such as persistence and collections. Persistent Programming
languages allow objects to be created and stored in a database and used directly from a

3
programming language. Allow data to be manipulated directly from the programming language no
need to go through SQL.
5.4.1. Abstraction
Process of identifying essential aspects of an entity and ignoring unimportant properties.
Concentrate on what an object is and what it does, before deciding how to implement it.
5.4.2. Encapsulation and Information Hiding
Encapsulation: Object contains both data structure and set of operations used to manipulate it.
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.
 One of the main characteristics of OO languages and systems.
 Class encapsulate data and the operations that work on the data in a single package.
 Related to the concepts of abstract data types and information hiding in programming
languages.
 Encapsulation means data and operations are packaged under one name and can be reused as
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.
5.4.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

4
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.
• Composite: At least one multi-valued attribute and no attributes refer to other object
• Compound: At least one attribute that references other object
• Hybrid: Repeating group of attributes and at least one refers to other object
5.4.4. Object Identity
An OO database system 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, or OID. The value of an OID is not visible to the external user, but it is used internally
by the system to identify each object uniquely and to create and manage inter-object references.
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. In C/C++, OID is

5
physical address in process memory space, which is too small - scalability requires that OIDs be
valid across storage volumes, possibly across different computers. Further, when object is deleted,
memory is reused, which may cause problems.
Advantages of OIDs:
 They are efficient.  They cannot be modified by the user.
 They are fast.  They are independent of content.
5.4.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.4.6. Classes, Subclasses, Superclasses and Inheritance
Class: Blueprint for defining a set of similar objects. Objects in a class are called instances. Class
is also an object with own class attributes and class methods. 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

6
BRANCH
Attributes
brabchNo
street
city
postcode
Methods
Print()
getPostCode()
numberofStaff()
Objects of BRANCH class

brabchNo=B005 brabchNo=B007 brabchNo=B003


street=st1 street=st2 street=st2
city=Addis city=Dire city=Bahirdar
postcode=1425 postcode=452 postcode=85
Class Instance Share Attributes and Methods.

Subclasses, Superclasses, and Inheritance: Inheritance allows one class of objects to be defined

7
as a special case of a more general class. Special cases are subclasses and more general cases are
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

8
5.4.7. Overriding and Overloading
Overriding: Process of redefining a property within a subclass. 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. Overloading
Print Method:

5.4.8. Polymorphism and Dynamic Binding


Polymorphism: Means ‘many forms’. Three types: operation, inclusion, and parametric.

9
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.

5.5. Storing Objects In Relational Database Systems


One approach to achieving persistence with an OOPL is to use an RDBMS as the underlying
storage engine. Requires mapping class instances (i.e. objects) to one or more tuples distributed
over one or more relations. To handle class hierarchy, have two basics tasks to perform:
1. Design relations to represent class hierarchy;
2. Design how objects will be accessed.

5.5.1. Mapping Classes to Relations


Number of strategies for mapping classes to relations, although each results in a loss of semantic
information.
1. Map each class or subclass to a relation:
Staff (staffNo, fName, lName, position, sex, DOB, salary)
Manager (staffNo, bonus, mgrStartDate)
SalesPersonnel (staffNo, salesArea, carAllowance)
Secretary (staffNo, typingSpeed)
2. Map each subclass to a relation:

10
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.5.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.
Naming and Reach ability
 Naming Mechanism: Assign an object a unique persistent name through which it can be
retrieved by this and other programs.
 Reach ability Mechanism: Make the object reachable from some persistent object. An
object B is said to be reachable from an object A if a sequence of references in the object
graph lead from object A to object B.

5.6. OODBMS
Object-oriented database technology is a marriage of object-oriented programming and database
technologies. Database management system integrates benefits of typical database systems with
OODM characteristics. Handles a mix of data types (since OODBMS permits new data definition)
OODBMS follows Object Oriented rules and also follows DBMS rules.

11
OO Data Model: A (logical) data model that captures the semantics of objects supported in object-
oriented programming.

OODB: A persistent and sharable collection of objects defined by an OODM.


Object-Orientation = abstract data types + inheritance + object identity;
OODBMS = object-orientation + database capabilities.
OODBMS: The manager of an OODB.
OODBMS must, at a minimum, satisfy:
1. It must provide database functionality;
2. It must support object identity;
3. It must provide encapsulation;
4. It must support objects with complex state.
OODBMS Advantages
• More semantic information
• Support for complex objects
• Extensibility of data types (user defined data types)
• May improve performance with efficient caching
• Versioning
• Polymorphism: one operation shared by many objects and each acting differently

12
• Reusability
• Inheritance speeds development and application: defining new objects in terms of
previously defined objects Incremental Definition)
• Potential to integrate DBMSs into single environment
• Relationship between objects is represented explicitly supporting both navigational and
associative access to information.
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 standard
• No single data model
• Steep learning curve
• Low market presence
5.6.1. OO Database Design and Implementation
 Provides data identification and the procedures for data manipulation
 Data and procedures self-contained entity
 Iterative and incremental
 DBA does more programming
 Lack of standards

5.7. OO Data modeling and E-R diagramming


Characteristics of OO Data Model
• Supports complex objects • Exhibit inheritance
• Must be extensible • Supports object identity
• Supports encapsulation

13
OO Data Model vs. E-R Data Model Components

OO Data Model E-R Model


Type Entity definition
Object Entity Instance
Class Entity set
Instance variable Attribute
N/A Primary key
OID N/A
Class hierarchy E-R diagram

14

Potrebbero piacerti anche