CSC475 · 2081 · 10 marks
Explain different object database concepts in brief. What are type constructors?
Explain different object database concepts in brief. What are type constructors?[10]
Quick answer
Object databases (also called Object-Oriented Databases) combine the advantages of object-oriented technologies with traditional database systems. The main goal is to improve the modeling of real-world concepts in the database.
Object Database Concepts and Type Constructors
Part 1: Object Database Concepts
Key Object Database Concepts
1. Object Identity
Every object in an object database has a unique, system-generated identifier called an Object Identifier (OID). Unlike relational databases where identity is based on key values, OIDs are independent of the object's attribute values and remain stable even if the data changes.
2. Complex Objects
Object databases support complex (composite) objects that can contain other objects as attributes. This allows modeling of real-world entities more naturally. For example, an Employee object can contain an Address object as an attribute.
3. Encapsulation
Object databases support encapsulation, which means that both data (attributes) and behavior (methods/operations) are bundled together within an object. External users interact with objects only through defined interfaces. This is provided through the mechanism of user-defined types.
4. Classes and Type Hierarchy
Objects are grouped into classes based on shared attributes and methods. Classes can be organized into a type hierarchy using inheritance, allowing subclasses to inherit properties and methods from superclasses. In SQL-based object databases, this is supported using the keyword UNDER.
5. Inheritance
Inheritance allows a new class (subclass) to derive properties and behaviors from an existing class (superclass). This promotes reusability and reduces redundancy. For example:
Person (superclass)
└── Employee UNDER Person (subclass)
└── Student UNDER Person (subclass)
6. Object References
Objects can reference other objects using reference types. This replaces the concept of foreign keys in relational databases and allows direct navigation between related objects.
7. Polymorphism
The same operation can behave differently on different types of objects. This allows flexible and extensible database design.
8. Object Query Language (OQL)
Object databases are queried using OQL (Object Query Language), which is an SQL-like declarative language. It provides:
- High-level primitives for object sets and structures
- Support for object identity and complex objects
- Syntax similar to SQL but extended with object-oriented features
9. Persistence
Objects in an object database are persistent, meaning they continue to exist beyond the execution of the program that created them, unlike transient objects in memory.
Part 2: Type Constructors
Type constructors are mechanisms used in object-relational and object databases to define complex or structured data types beyond the basic primitive types (integer, string, etc.).
Definition
A type constructor is a mechanism that allows the creation of new, complex data types by combining or structuring existing types.
Two Main Categories of Type Constructors
1. Row Type (Tuple / Struct) Constructor
- Used to create a structured type that groups multiple attributes together, similar to a record or struct.
- Allows a single attribute to hold multiple sub-attributes.
- Example:
CREATE TYPE Address AS (
street VARCHAR(50),
city VARCHAR(30),
zipcode CHAR(10)
) NOT FINAL;
Here, Address is a row type that groups street, city, and zipcode into a single structured type.
2. Collection Type Constructor
Collection types allow an attribute to hold multiple values of the same type. There are three main collection type constructors:
| Constructor | Description |
|---|---|
| Set | An unordered collection of unique elements (no duplicates) |
| List | An ordered collection of elements (duplicates allowed) |
| Bag (Multiset) | An unordered collection where duplicates are allowed |
Example:
-- A SET of phone numbers for an employee
CREATE TYPE PhoneSet AS SET(VARCHAR(15));
-- Using it in a table
CREATE TABLE Employee (
emp_id INT,
name VARCHAR(50),
phones PhoneSet
);
Additional Mechanisms Related to Type Constructors
| Feature | Description |
|---|---|
| Reference Type | Specifies object identifiers to allow one object to reference another |
| Encapsulation | Operations are encapsulated within user-defined types |
| Inheritance (UNDER) | New types can be derived from existing types using the UNDER keyword |
Summary Table
| Concept | Description |
|---|---|
| Object Identity | Unique OID for every object |
| Encapsulation | Data + behavior bundled together |
| Inheritance | Subclass inherits from superclass using UNDER |
| Complex Objects | Objects containing other objects |
| OQL | SQL-like language for querying objects |
| Row Type Constructor | Groups multiple attributes into one structured type |
| Collection Type Constructor | Set, List, Bag for multi-valued attributes |
| Reference Type | Mechanism for object-to-object references |
Conclusion
Object database concepts extend traditional relational databases by incorporating object-oriented principles such as identity, encapsulation, inheritance, and complex types. Type constructors, specifically row type (tuple/struct) and collection type (set, list, bag) constructors, are fundamental tools that enable the definition of rich, complex data structures needed to model real-world entities accurately.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.