Concepts for Object-Oriented Databases – Advanced Database Systems

Meta Description: Learn the fundamental concepts of Object-Oriented Databases including object identity, object structure, type constructors, encapsulation, and inheritance in this comprehensive lesson for Advanced Database Systems students.


1. Overview of Object-Oriented Concepts

1.1 What is an Object?

An object is a way of thinking about and representing real-world things in programming. It matches how humans naturally see and understand the world around them.

Important Points:
  • Objects are like real-world things (nouns)
  • Objects have both data (attributes) and actions (methods)
  • Objects help us model real-world problems naturally

Detailed Explanation:

Think about a car in the real world. A car has:

  • Properties: color, brand, model, speed
  • Actions: accelerate, brake, turn

In object-oriented programming, we create a “Car” object that has both these properties and actions together in one package. This is similar to how we think about cars in real life – we don’t separate the car’s properties from what it can do.

Real World Object: CAR
+----------------------------------+
|  Properties (Data)               |
|  - Color: Red                    |
|  - Brand: Toyota                 |
|  - Speed: 120 km/h               |
+----------------------------------+
|  Actions (Methods)               |
|  - Accelerate()                  |
|  - Brake()                       |
|  - Turn()                        |
+----------------------------------+

Example:

A “Student” object would have:

  • Properties: name, ID, age, grade
  • Actions: study(), takeExam(), getGrade()
Exam Question:
Which of the following best describes an object in object-oriented programming?

A) Only data stored in a database
B) A real-world entity with both data and operations
C) A function that performs calculations
D) A variable that holds a single value

1.2 What are Object-Oriented Databases (OODBS)?

Important Points:
  • OODBS stores data together with methods for accessing it
  • It can handle complex data types (like CAD designs)
  • It can store many different data types in one database
  • It makes it easier to track objects over time

Detailed Explanation:

Traditional databases (relational databases) store data in tables with rows and columns. However, they have limitations when dealing with complex data like images, videos, or engineering designs.

Object-Oriented Database Systems (OODBS) solve these problems by:

  1. Storing data with methods: The data and the code to manipulate it are stored together
  2. Handling complex data: Can store complex structures like designs, images, and documents
  3. Supporting multiple data types: Can store text, images, audio, video, and structured data in the same database
  4. Tracking object evolution: Can follow how objects change over time
Traditional Database          Object-Oriented Database
+-------------------+         +-------------------+
| Data only         |         | Data + Methods    |
| Simple tables     |         | Complex objects   |
| Fixed structure   |         | Flexible structure|
+-------------------+         +-------------------+

Example:

In a Computer-Aided Design (CAD) application:

  • A traditional database would struggle to store complex 3D models
  • An OODBS can store the 3D model as an object with all its properties and the methods to manipulate it
Exam Question:
One of the following is NOT a capability of Object-Oriented Database Systems:

A) Storing complex data types
B) Storing a wide range of data types in the same database
C) Only storing simple text and numbers
D) Tracking objects through time

1.3 Applications of Object-Oriented Databases

Important Points:
  • OODBS was first used in CAD and CAM applications
  • Now used in telecommunications, healthcare, finance, and multimedia
  • Ideal for applications with complex data relationships

Detailed Explanation:

Object-Oriented Databases have evolved from specialized applications to broader use:

Early Applications:

ApplicationFull NameWhy OODBS?
CADComputer-Aided DesignComplex design objects with many relationships
CAMComputer-Aided ManufacturingComplex manufacturing processes and data

Modern Applications:

FieldExample Use
TelecommunicationsNetwork management, call routing
HealthcareMedical imaging, patient records
FinanceTrading systems, risk analysis
MultimediaVideo streaming, image databases
Document ManagementContent management systems

Example:

In healthcare, an OODBS can store:

  • Patient information (text)
  • X-ray images (images)
  • Medical history documents (documents)
  • Treatment methods (code/procedures)
Exam Question:
Which were the FIRST application areas where OODBMS were widely used?

A) Telecommunications and Healthcare
B) Finance and Multimedia
C) CAD and CAM
D) Document management and Text processing

1.4 Basic Data Representation Terminology

Important Points:
  • Attribute: A named column in a table (property)
  • Relation: A table that stores related data
  • Tuple: A row in a table (a record)

Detailed Explanation:

Before diving deeper into object-oriented concepts, let’s understand the basic terminology:

         RELATION (Table)
+-----------------------------------+
|  Attribute  |  Attribute  |  Attr |
|   (Name)    |   (Age)     | (City)|
+-------------+-------------+-------+
|    Abebe    |     25      | Addis |  <-- Tuple (Row)
+-------------+-------------+-------+
|    Tigist   |     22      | Gondar|  <-- Tuple (Row)
+-------------+-------------+-------+

Definitions:

  • Attribute: A named column that represents a property. Example: "Student_Name" is an attribute that stores names of students.
  • Relation: A table that contains related data. Example: A "Students" table containing student information.
  • Tuple: A row in a table representing one complete record. Example: (Abebe, 25, Addis) is one tuple.

Example:

For a "Courses" relation:

  • Attributes: Course_ID, Course_Name, Credit_Hours
  • Tuple: (CS101, "Database Systems", 3)
Exam Question:
In a database table called "Employees" with columns Emp_ID, Name, and Salary, what is a single row containing (101, "Aster", 5000) called?

A) An Attribute
B) A Relation
C) A Tuple
D) A Column


2. Object Identity, Object Structure and Type Constructors

2.1 Understanding Object Identity

Important Points:
  • Each object has a unique identity called OID
  • OID is system-generated, not user-supplied
  • OID is invisible to external users
  • Object identity is stronger than primary keys in relational databases

Detailed Explanation:

In object-oriented databases, every object gets a unique identifier that distinguishes it from all other objects, even if they have identical data.

What is OID (Object Identifier)?

OID is a unique, system-generated identifier assigned to each object when it is created. Unlike primary keys in relational databases:

  • OID is automatically generated by the system
  • Users cannot see or modify the OID
  • OID is used internally to reference objects
  • OID never changes throughout the object's lifetime
Object Identity Comparison:

Relational Database:
+-------------------+
| Student Table     |
| ID (Primary Key)  |  <-- User can see and may change
| Name              |
| Age               |
+-------------------+

Object-Oriented Database:
+-------------------+
| Student Object    |
| OID: #7A3F2B      |  <-- System-generated, invisible to user
| Name: Abebe       |
| Age: 21           |
+-------------------+

Why is Object Identity Important?

  1. Uniqueness: Two objects with identical data are still different objects
  2. Reference: Objects can refer to each other using OIDs
  3. Persistence: Objects maintain identity even when their data changes

Example:

Consider two Employee objects:

  • Employee A: Name = "Abebe", Age = 30, OID = #X100
  • Employee B: Name = "Abebe", Age = 30, OID = #X101

Even though they have the same data, they are different objects because they have different OIDs.

Exam Question:
Which statement about Object Identifier (OID) is TRUE?

A) OID is visible to external users
B) OID can be changed by the database administrator
C) OID is a unique, system-generated identifier
D) OID is the same as a primary key in relational databases

2.2 Properties of Object Identifier (OID)

Important Points:
  • OID is immutable (cannot be changed)
  • Each OID is used only once (never reused)
  • Even deleted objects' OIDs are not reassigned

Detailed Explanation:

OID has two critical properties that ensure data integrity:

Property 1: Immutability

The OID of an object, once assigned, never changes. This means:

  • Even if the object's data changes completely, its OID stays the same
  • References to the object remain valid throughout its lifetime
See also  Transaction Processing Concepts - Advanced Database Systems

Property 2: Single Use

Each OID is used only once in the entire history of the database:

  • When an object is deleted, its OID is retired forever
  • A new object will get a completely new OID
  • This prevents confusion from old references pointing to new objects
OID Lifecycle:

Create Object A  -->  OID: #001 assigned
                      |
                      v
Modify Object A  -->  OID: #001 (unchanged)
                      |
                      v
Delete Object A  -->  OID: #001 retired (never reused)
                      |
                      v
Create Object B  -->  OID: #002 assigned (new OID)

Example:

If a student object with OID #1001 is deleted, no future student will ever get OID #1001, even if there are millions of new students added later.

Exam Question:
What happens to an OID when an object is deleted from an OODB?

A) It is reassigned to the next object created
B) It is stored for future reference
C) It is never reused for any new object
D) It is returned to a pool of available IDs

2.3 Forms of Object Identity

Important Points:
  • Value-based identity: Uses data values (like primary keys)
  • Name-based identity: Uses user-supplied names
  • Built-in identity: System-generated (used in OODB)

Detailed Explanation:

Object identity can be represented in three different ways:

1. Value-Based Identity

  • Uses data values to identify objects
  • Common in relational databases
  • Example: Student_ID = "STU001" identifies a student
  • Problem: If the value changes, identity changes

2. Name-Based Identity

  • Uses user-supplied names
  • Common in programming variables
  • Example: Variable name "studentRecord"
  • Problem: Limited scope and user-dependent

3. Built-in Identity

  • Identity is built into the data model
  • Used in object-oriented systems
  • No user-supplied identifier needed
  • Most robust form of identity
Forms of Identity Comparison:

+------------------+-------------------+-------------------+
|     Form         |     Example       |     System        |
+------------------+-------------------+-------------------+
| Value-based      | Primary Key       | Relational DB     |
| Name-based       | Variable name     | Programming       |
| Built-in         | OID               | Object-Oriented   |
+------------------+-------------------+-------------------+

Example:

In a university database:

  • Value-based: Student with ID "U001" - identity depends on ID value
  • Name-based: "currentStudent" variable - identity is the name
  • Built-in: Internal OID #7F2A - identity is system-generated
Exam Question:
Which form of identity is used in Object-Oriented Database Systems?

A) Value-based identity
B) Name-based identity
C) Built-in identity
D) User-defined identity

2.4 Object Structure

Important Points:
  • Objects have state (current value) constructed using type constructors
  • Objects are formally represented as triple (i, c, v)
  • i = unique OID, c = type constructor, v = object state
  • Allows nesting of constructors for complex objects

Detailed Explanation:

In object-oriented databases, every object has a structure that can be described formally. An object is represented as a triple with three components:

The Object Triple: (i, c, v)

ComponentMeaningDescription
iObject IdentifierUnique OID for the object
cType ConstructorHow the object state is constructed
vObject StateCurrent value of the object

Understanding Each Component:

  1. Object Identifier (i): The unique system-generated ID
  2. Type Constructor (c): Indicates how the object's state is built (atom, tuple, set, etc.)
  3. Object State (v): The actual data stored in the object
Object Structure Example:

Student Object = (i, c, v)

i = #OID12345 (unique identifier)
c = tuple (type constructor)
v = {
      name: "Abebe",
      age: 21,
      courses: { "CS101", "CS102", "CS103" }
    }

Visual representation:
+----------------------------------+
| OID: #OID12345                   |
| Type: Tuple                      |
+----------------------------------+
| State:                           |
|   name: "Abebe"                  |
|   age: 21                        |
|   courses: {"CS101","CS102",...} |
+----------------------------------+

Example:

A "Department" object might be:

  • i = #DEPT001
  • c = tuple
  • v = {name: "Computer Science", location: "Building A", students: {set of student objects}}
Exam Question:
In the object triple (i, c, v), what does 'c' represent?

A) The object's unique identifier
B) The type constructor
C) The object's current state
D) The object's class name

2.5 Type Constructors

Important Points:
  • Type constructors define how object states are built
  • Three basic constructors: atom, tuple, set
  • Other constructors: list, bag, array
  • Constructors can be nested to create complex objects

Detailed Explanation:

Type constructors are the building blocks used to create complex object structures. Think of them as templates or patterns for organizing data.

The Three Basic Type Constructors:

A. Atom Constructor

The atom constructor represents basic, indivisible values:

  • Integers: 1, 42, -7
  • Real numbers: 3.14, 2.718
  • Character strings: "Hello", "Database"
  • Booleans: true, false
Atom Constructor Examples:

Integer Atom:    42
                 |
                 +-- Single, indivisible value

String Atom:     "Hello World"
                 |
                 +-- Single text value

Boolean Atom:    TRUE
                 |
                 +-- Single logical value

B. Tuple Constructor

The tuple constructor groups multiple related values:

  • Similar to a record or struct
  • Each component has a name and a value
  • Can contain atoms or other complex objects
Tuple Constructor Example:

Student Tuple:
+------------------------+
| name: "Aster"          |  <-- Atom (string)
| age: 22                |  <-- Atom (integer)
| gpa: 3.85              |  <-- Atom (real)
+------------------------+

Formal: tuple{name: atom, age: atom, gpa: atom}

C. Set Constructor

The set constructor represents a collection of unordered, unique elements:

  • Elements have no specific order
  • No duplicates allowed
  • Can contain atoms or complex objects
Set Constructor Example:

Course_Set: { "CS101", "CS102", "CS103" }

Properties:
- Unordered: {CS101, CS102} = {CS102, CS101}
- Unique: Cannot have duplicate values

Formal: set{atom, atom, atom}

Other Type Constructors:

ConstructorDescriptionExample
ListOrdered collection, duplicates allowed[1, 2, 3, 2, 1]
BagUnordered collection, duplicates allowed{a, b, a, c}
ArrayOrdered collection with index accessarr[0]=5, arr[1]=10

Example of Nested Constructors:

Complex Object with Nested Constructors:

University Object:
+------------------------------------------+
| name: "Addis Ababa University"           | (atom)
| departments: {                           | (set)
|     tuple{name: "CS", students: list{...}},|
|     tuple{name: "Math", students: list{...}}|
|   }                                      |
| established: 1950                        | (atom)
+------------------------------------------+

Structure: tuple{
    name: atom,
    departments: set(tuple),
    established: atom
}
Exam Question:
Which type constructor would you use to represent a student's first name "Abebe"?

A) Tuple Constructor
B) Set Constructor
C) Atom Constructor
D) List Constructor


3. Encapsulation of Operations, Methods and Persistence

3.1 Understanding Encapsulation

Important Points:
  • Encapsulation hides internal details of objects
  • Objects are accessed only through predefined operations
  • Related to abstract data types and information hiding
  • One of the main characteristics of OO systems

Detailed Explanation:

Encapsulation is a fundamental concept in object-oriented systems that protects data and organizes code. It is like a protective capsule around an object's data.

What is Encapsulation?

Encapsulation means bundling data (variables) and methods (functions) together inside an object, while hiding the internal details from the outside world.

Key Ideas of Encapsulation:

  1. Data Hiding: The internal structure of the object is hidden from external access
  2. Controlled Access: Objects can only be accessed through predefined operations (methods)
  3. Interface-Based: External users only see the interface, not the implementation
Encapsulation Visualization:

+----------------------------------+
|         OBJECT                   |
|  +--------------------------+    |
|  |   Hidden Data (Private)  |    |
|  |   - Internal variables   |    |
|  |   - Implementation code  |    |
|  +--------------------------+    |
|                                  |
|  +--------------------------+    |
|  |   Public Interface       |    |
|  |   - Operation 1          |<---|--- External Access
|  |   - Operation 2          |    |
|  |   - Operation 3          |    |
|  +--------------------------+    |
+----------------------------------+

Example:

Consider a "Bank Account" object:

  • Hidden Data: balance, accountNumber, transactionHistory
  • Public Operations: deposit(), withdraw(), getBalance()

Users cannot directly change the balance; they must use deposit() or withdraw() methods.

Exam Question:
What is the main purpose of encapsulation in object-oriented databases?

A) To make all data publicly accessible
B) To hide internal details and allow access through predefined operations
C) To increase the size of objects
D) To slow down database operations

3.2 Operations on Objects

Important Points:
  • Operations are the only way to interact with encapsulated objects
  • Operations can create, destroy, update, or retrieve object data
  • The interface defines what operations are available

Detailed Explanation:

Operations define what actions can be performed on an object. They form the bridge between external users and internal data.

Types of Operations:

Operation TypePurposeExample
Create/InsertMake new objectscreateStudent()
Destroy/DeleteRemove objectsdeleteStudent()
UpdateModify object stateupdateGrade()
RetrieveGet object informationgetName(), getGPA()
Object Operations Flow:

         Create Object
              |
              v
    +------------------+
    |    OBJECT        |<---- Retrieve data
    |                  |<---- Update state
    +------------------+<---- Query information
              |
              v
        Destroy Object

Example:

For a "Book" object in a library database:

  • createBook(title, author, ISBN): Creates a new book record
  • deleteBook(): Removes the book from database
  • borrowBook(memberID): Updates status to "borrowed"
  • returnBook(): Updates status to "available"
  • getInfo(): Returns book details

3.3 Signature and Methods

Important Points:
  • Signature: The interface part of an operation (name and parameters)
  • Method: The actual implementation code
  • Methods are invoked by sending messages to objects

Detailed Explanation:

Understanding the difference between signature and method is important for understanding encapsulation:

Signature:

  • The public interface of an operation
  • Defines the operation name
  • Defines the parameters (arguments) the operation accepts
  • Defines the return type
  • External users only see the signature

Method:

  • The actual implementation code
  • Contains the logic that performs the operation
  • Hidden from external users
  • Invoked when a message is sent to the object
Signature vs Method:

+------------------------------------------+
|              OPERATION                    |
|                                          |
|  Signature (Public Interface):            |
|  +------------------------------------+  |
|  | deposit(amount: money) : boolean   |  |
|  +------------------------------------+  |
|                                          |
|  Method (Hidden Implementation):         |
|  +------------------------------------+  |
|  | if amount > 0 then                 |  |
|  |   balance = balance + amount       |  |
|  |   return true                      |  |
|  | else                               |  |
|  |   return false                     |  |
|  +------------------------------------+  |
+------------------------------------------+

Example:

For a "Student" object:

SignatureMethod Purpose
addCourse(courseID): booleanAdds a course to student's list, returns success/failure
calculateGPA(): realComputes and returns the GPA
setName(newName): voidUpdates the student's name

Message Passing:

To execute a method, you send a message to the object:

  • Message includes: operation name and arguments
  • Object receives the message and executes the corresponding method
Exam Question:
What is the difference between a signature and a method?

A) They are the same thing
B) Signature is the interface, method is the implementation
C) Signature is hidden, method is public
D) Method has no parameters, signature has parameters

3.4 Visible and Hidden Attributes

Important Points:
  • For database applications, complete encapsulation is too strict
  • Attributes are divided into visible and hidden
  • Visible attributes can be read directly by queries
  • Hidden attributes require methods for access

Detailed Explanation:

In pure object-oriented programming, all data is completely encapsulated. However, for database applications, this is often too restrictive. Therefore, OODB systems divide object attributes into two categories:

Visible Attributes:

  • Can be directly accessed for reading
  • Accessible by external operators
  • Can be queried using high-level query languages
  • Similar to public fields in some programming languages

Hidden Attributes:

  • Completely encapsulated
  • Can only be accessed through predefined operations
  • Protected from direct external access
  • Provides security for sensitive data
Object with Visible and Hidden Attributes:

+------------------------------------------+
|          EMPLOYEE OBJECT                  |
|                                          |
|  Visible Attributes:                      |
|  +------------------------------------+  |
|  | name: "Aster"         (Read OK)    |  |
|  | department: "Finance"  (Read OK)   |  |
|  | position: "Manager"    (Read OK)   |  |
|  +------------------------------------+  |
|                                          |
|  Hidden Attributes:                       |
|  +------------------------------------+  |
|  | salary: 50000         (Read via    |  |
|  | bonus: 10000            methods    |  |
|  | password: "***"         only)      |  |
|  +------------------------------------+  |
+------------------------------------------+

Access Rules:
- name --> Direct read allowed
- salary --> Must use getSalary() method
- password --> Must use verifyPassword() method

Example:

In a "Patient" object for a hospital database:

  • Visible: name, age, bloodType (doctors need quick access)
  • Hidden: medicalHistory, insuranceDetails (sensitive information)
Exam Question:
In an OODB, why are attributes divided into visible and hidden categories?

A) To make all data accessible
B) Because complete encapsulation is too strict for database applications
C) To increase database size
D) To make queries slower


4. Type and Class Hierarchies and Inheritance

4.1 Understanding Inheritance

Important Points:
  • Inheritance allows new types to be based on existing types
  • Creates a hierarchy of classes
  • Enables code reusability
  • Objects inherit characteristics from parent classes

Detailed Explanation:

Inheritance is one of the most powerful concepts in object-oriented programming and databases. It allows you to create new classes based on existing ones, inheriting their properties and methods.

Key Concepts of Inheritance:

  1. Code Reusability: Write code once, use it in multiple places
  2. Hierarchical Organization: Organize classes in a logical hierarchy
  3. Shared Behavior: Parent classes share their features with children
  4. Extension: Child classes can add new features
Basic Inheritance Structure:

        +----------------+
        |    Animal      |
        |  - head        |
        |  - body        |
        |  + feed()      |
        +----------------+
              /   \
             /     \
    +--------+     +--------+
    | Mammal |     |  Fish  |
    | + legs |     | + fins |
    | + sit()|     | +swim()|
    +--------+     +--------+

Mammal inherits: head, body, feed() from Animal
Mammal adds: legs, sit()

Fish inherits: head, body, feed() from Animal
Fish adds: fins, swim()

Example:

Consider a university database:

  • Person class: name, address, dateOfBirth, getAge()
  • Student class (inherits Person): studentID, courses, calculateGPA()
  • Employee class (inherits Person): employeeID, salary, calculateTax()

Student and Employee both inherit name, address, and getAge() from Person, but add their own unique attributes and methods.

Exam Question:
What is the main benefit of inheritance in object-oriented databases?

A) It makes the database slower
B) It enables code reusability
C) It prevents classes from having any relationships
D) It increases the number of tables

4.2 Superclass and Subclass

Important Points:
  • Superclass: The more general class (parent)
  • Subclass: The specialized class (child)
  • Subclass inherits all properties from superclass
  • Subclass can add new properties and methods
  • Subclass can redefine inherited methods

Detailed Explanation:

Understanding the relationship between superclass and subclass is fundamental to inheritance:

Superclass:

  • Also called parent class or base class
  • Contains common/general properties and methods
  • Located at the top or middle of the hierarchy

Subclass:

  • Also called child class or derived class
  • Contains specialized properties and methods
  • Automatically inherits all properties from superclass
  • Can add new properties not in superclass
  • Can override (redefine) inherited methods
Superclass and Subclass Relationship:

        +================+
        |   VEHICLE      |  <-- SUPERCLASS
        |   (General)    |
        +================+
        | - licenseNo    |
        | - color        |
        | + start()      |
        | + stop()       |
        +================+
              /   \
             /     \
   +---------+     +-----------+
   |   CAR   |     |   BIKE    |  <-- SUBCLASSES
   |(Special)|     | (Special) |
   +---------+     +-----------+
   | + doors |     | + pedals  |
   | +drive()|     | + pedal() |
   +---------+     +-----------+

Both Car and Bike inherit:
- licenseNo, color, start(), stop()

Car adds: doors, drive()
Bike adds: pedals, pedal()

Important Rule:

If class B is a subclass of class A:

  • Every instance of B is automatically an instance of A
  • The reverse is NOT true - an instance of A is NOT necessarily an instance of B

Example:

  • Every Car is a Vehicle (TRUE)
  • Every Vehicle is a Car (FALSE - could be a Bike, Truck, etc.)
Exam Question:
If "GraduateStudent" is a subclass of "Student", which statement is TRUE?

A) Every Student is a GraduateStudent
B) Every GraduateStudent is a Student
C) GraduateStudent cannot have any new attributes
D) Student inherits properties from GraduateStudent

4.3 Type (Class) Hierarchy

Important Points:
  • Type hierarchy classifies entities into subclasses
  • Two types: Specialization and Generalization
  • Specialization: Start from superclass, create subclasses
  • Generalization: Start from subclasses, create superclass

Detailed Explanation:

Class hierarchy organizes classes in a tree-like structure based on their relationships. There are two approaches to creating this hierarchy:

1. Specialization (Top-Down Approach)

Specialization is the process of creating subclasses from a superclass:

  • Start with a general superclass
  • Identify specific characteristics that distinguish groups
  • Create subclasses for each distinct group
Specialization Process:

Step 1: Start with Superclass
        +------------+
        |   PERSON   |
        +------------+

Step 2: Identify Distinct Groups
        - Some are students
        - Some are employees

Step 3: Create Subclasses
        +------------+
        |   PERSON   |
        +------------+
           /      \
    +--------+  +----------+
    |STUDENT |  | EMPLOYEE |
    +--------+  +----------+

Direction: Top → Down (Superclass to Subclasses)

Example:

Starting with "Account" class:

  • Identify: Some accounts are Savings, some are Checking
  • Create: SavingsAccount and CheckingAccount as subclasses

2. Generalization (Bottom-Up Approach)

Generalization is the reverse process - creating a superclass from existing classes:

  • Start with multiple similar classes
  • Identify common properties
  • Create a superclass with the common properties
Generalization Process:

Step 1: Start with Separate Classes
        +--------+     +----------+
        |  CAR   |     |   BIKE   |
        +--------+     +----------+
        Both have: licenseNo, color, start()

Step 2: Identify Common Properties
        Common features extracted

Step 3: Create Superclass
        +------------+
        |  VEHICLE   |
        +------------+
        | licenseNo  |
        | color      |
        | start()    |
        +------------+
           /      \
    +--------+  +----------+
    |  CAR   |  |   BIKE   |
    +--------+  +----------+

Direction: Bottom → Up (Subclasses to Superclass)

Example:

Starting with "Lion", "Tiger", "Elephant" classes:

  • Identify: All have name, age, habitat, eat(), sleep()
  • Create: "Animal" superclass with common properties
Exam Question:
What is the difference between specialization and generalization?

A) They are exactly the same
B) Specialization goes from superclass to subclasses, generalization goes from subclasses to superclass
C) Specialization creates fewer classes, generalization creates more classes
D) Specialization is for databases, generalization is for programming

4.4 Practical Inheritance Examples

Important Points:
  • Inheritance models real-world relationships
  • Multiple levels of inheritance can exist
  • Subclasses can be superclasses to other classes

Detailed Explanation:

Let's look at a comprehensive example of inheritance:

Example: University System

University Class Hierarchy:

                    +---------------+
                    |    PERSON     |
                    +---------------+
                    | - name        |
                    | - address     |
                    | - dateOfBirth |
                    +---------------+
                    | + getAge()    |
                    | + getName()   |
                    +---------------+
                          /    \
           +--------------+    +---------------+
           |   STUDENT    |    |   EMPLOYEE    |
           +--------------+    +---------------+
           | - studentID  |    | - employeeID  |
           | - major      |    | - department  |
           +--------------+    | - salary      |
           | + getGPA()   |    +---------------+
           +--------------+    | + calcTax()   |
                  |            +---------------+
                  |                   |
         +--------+--------+   +------+------+
         | GRADUATE STUDENT|   |   FACULTY   |
         +-----------------+   +-------------+
         | - thesisTopic   |   | - rank      |
         +-----------------+   | - specialty |
         | + defendThesis()|   +-------------+
         +-----------------+   | + promote() |
                               +-------------+

Inheritance Chain:
Faculty → Employee → Person
GraduateStudent → Student → Person

What Each Class Inherits:

ClassInherits FromAdds
StudentPersonstudentID, major, getGPA()
EmployeePersonemployeeID, department, salary, calcTax()
GraduateStudentStudentthesisTopic, defendThesis()
FacultyEmployeerank, specialty, promote()
Exam Question:
In a class hierarchy where "Faculty" is a subclass of "Employee" and "Employee" is a subclass of "Person", what properties would "Faculty" have?

A) Only properties defined in Faculty
B) Properties from Faculty and Employee only
C) Properties from Faculty, Employee, and Person
D) Only properties from Person


Exam Tips

Key Points to Remember for Exams:

  1. Object vs. Traditional Data: Objects combine data and methods; traditional databases separate them.
  2. OID Properties: Remember the two key properties - immutable (cannot change) and single-use (never reused).
  3. Object Triple (i, c, v): Know what each component represents: i = OID, c = type constructor, v = state.
  4. Type Constructors: Memorize the three basic ones: atom, tuple, set. Know their characteristics.
  5. Encapsulation: Understand the difference between signature (interface) and method (implementation).
  6. Visible vs. Hidden: Visible = direct access; Hidden = method access only.
  7. Superclass vs. Subclass: Subclass inherits from superclass; every subclass instance is a superclass instance.
  8. Specialization vs. Generalization: Specialization = top-down; Generalization = bottom-up.
  9. Applications: Remember CAD/CAM were the first application areas for OODB.

Practice Challenge Questions for Exam Preparation

Question 1:
Explain why Object-Oriented Databases are better suited for Computer-Aided Design (CAD) applications than traditional relational databases.

Question 2:
Given the following object representation: (#OBJ001, tuple, {name: "Lake Tana", location: "Bahir Dar", depth: 15, area: 2156}), identify:
a) The object identifier
b) The type constructor
c) The object state
d) What type of object this might represent

Question 3:
Design a class hierarchy for a library system with the following requirements:
- All items have an ID, title, and acquisition date
- Books have an author and ISBN
- Journals have a publisher and issue number
- E-books have a file format and download link

Draw the hierarchy and show what each class inherits.

Question 4:
Compare and contrast value-based identity and built-in identity. Give an example of each.

Question 5:
A database needs to store employee information. The system designers want to use encapsulation but also need efficient queries on most attributes. Explain how they should design the object structure.


This completes Chapter One: Concepts for Object-Oriented Databases. Make sure to review all sections and practice the questions before your exam. Good luck!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top