Object-Oriented & Other Models
While the Relational model dominates, some applications (CAD tools, multimedia databases, scientific simulations) handle complex data structures that are difficult to represent in flat tables.
Two models evolved to address this: the Object-Oriented Data Model (OODM) and the Object-Relational Model (ORDBMS).
Learning Objectives
After completing this chapter, you will be able to:
- Explain the Object-Oriented Data Model and its features.
- Understand Object-Relational Impedance Mismatch.
- Describe the Object-Relational model and its advantages.
- Compare OO, OR, and Relational models.
- Explain why PostgreSQL is Object-Relational.
- Answer interview questions on OO and OR models.
Object-Oriented Data Model (OODM)
Concept: Data is stored as Objects — just like in Java, Python, or C++.
| Feature | Description |
|---|---|
| Encapsulation | Data and the methods that operate on it are stored together |
| Inheritance | Objects inherit attributes and methods from parent objects |
| Polymorphism | Same method name can behave differently for different objects |
| Object Identity | Each object has a unique OID (Object Identifier) |
Pros and Cons
| Pros | Cons |
|---|---|
| Natural for complex data (audio, video, spatial) | Not standardized (no universal query language) |
| Reusable via inheritance | Complex and slower for simple queries |
| Good for CAD, GIS, multimedia | Poor at handling large-scale simple transactions |
Examples: ObjectStore, Versant Object Database.
Object-Relational Impedance Mismatch
This is a fundamental problem when using OOP languages with relational databases.
| OOP Concept | Relational Equivalent | Problem |
|---|---|---|
| Object | Row (tuple) | Objects have behavior (methods); rows are passive data |
| Class | Table | Class inheritance ≠ table relationships |
| Encapsulation | No direct equivalent | All data in a row is visible |
| References (pointers) | Foreign keys | Navigating references requires JOINs (slower) |
| Collections (lists, sets) | Separate tables | Requires additional queries |
Developers must manually map between the two paradigms. This is why ORMs (Object-Relational Mappers) like Hibernate (Java), Entity Framework (.NET), SQLAlchemy (Python), and Prisma (Node.js) exist — they automate the translation.
Object-Relational Model (ORDBMS)
A hybrid that adds object-oriented features to a standard relational database.
| Feature | What It Adds |
|---|---|
| User-defined types (UDTs) | Custom data types beyond built-in ones |
| Composite attributes | Nested structures within columns |
| Methods/functions | Behavior attached to data types |
| Inheritance | Table inheritance (one table extends another) |
| Array/JSON columns | Store complex structures in a single column |
Examples
| Database | Object-Relational Features |
|---|---|
| PostgreSQL | User-defined types, table inheritance, arrays, JSONB, custom functions |
| Oracle | Object types, VARRAYs, nested tables, methods |
| SQL Server | CLR integration, JSON, hierarchical data |
PostgreSQL is the prime example — it’s a relational database that also supports arrays, JSONB, custom types, table inheritance, and user-defined functions with multiple language support.
Model Comparison
| Feature | Relational | OO | OR (Hybrid) |
|---|---|---|---|
| Data unit | Row in table | Object | Row with complex types |
| Query language | SQL | Object query (non-standard) | SQL + extensions |
| Relationships | Foreign keys | Pointers/OIDs | Both |
| Inheritance | No | Yes | Table inheritance |
| ACID | Yes | Limited | Yes |
| Scalability | Excellent | Poor | Excellent |
| Complex data | Poor | Good | Good |
Why the OO Model Didn’t Win
| Reason | Explanation |
|---|---|
| No standard query language | Every OODBMS had its own API |
| Poor performance at scale | Object navigation is slower than set-based SQL |
| Lock-in | Hard to migrate between OODBMS vendors |
| Relational is “good enough” | ORMs bridge the gap for most apps |
| Web-scale demands consistency | Relational ACID is proven at scale |
The pragmatic solution won: relational databases with ORMs for the OOP mapping, and object-relational features in databases like PostgreSQL for when you need more.
Interview Deep Dive
Q: Why don’t we use OO databases for banking systems?
A: Banks require massive scalability and strict ACID properties for millions of simple transactions. The Relational model is mathematically optimized for set-based operations (debit this, credit that). The OO model’s object management overhead makes it inefficient for simple ledger entries.
Q: What is Object-Relational Impedance Mismatch?
A: The difficulty of mapping object-oriented programming concepts (objects, inheritance, polymorphism) to relational database tables (rows, columns, foreign keys). This mismatch is why ORMs like Hibernate, Prisma, and SQLAlchemy exist — they bridge the gap automatically.
Q: Is PostgreSQL purely Relational?
A: No — it is Object-Relational. It supports user-defined composite types, arrays, JSONB (binary JSON), table inheritance, and custom functions. These are object-oriented features embedded in a relational database.
Q: What’s the downside of using an ORM?
A: ORMs can generate inefficient SQL (N+1 query problems, large JOINs), hide the complexity of what the database is actually doing, and make it harder to optimize queries. For complex queries, raw SQL often performs better.
Key Takeaways
- The Object-Oriented Data Model stores data as objects with encapsulation, inheritance, and methods — ideal for complex data but not standardized.
- Impedance Mismatch is the fundamental difficulty of mapping OOP concepts to relational tables.
- ORMs (Hibernate, Prisma, SQLAlchemy) bridge the gap between OOP and relational databases.
- The Object-Relational Model combines relational tables with OO features (custom types, inheritance, arrays).
- PostgreSQL is the most popular Object-Relational database.
- Most developers use relational databases with ORMs — the OO model didn’t win for mainstream use.
Premium Content
Unlock Object-Oriented & Other Models and all premium lessons with a subscription.
From ₹199.99/year — See plans