Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Object-Oriented & Other Models
DBMS

Object-Oriented & Other Models

A quick look at Object-Oriented and Object-Relational models used for complex data.

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

FeatureDescription
EncapsulationData and the methods that operate on it are stored together
InheritanceObjects inherit attributes and methods from parent objects
PolymorphismSame method name can behave differently for different objects
Object IdentityEach object has a unique OID (Object Identifier)

Pros and Cons

ProsCons
Natural for complex data (audio, video, spatial)Not standardized (no universal query language)
Reusable via inheritanceComplex and slower for simple queries
Good for CAD, GIS, multimediaPoor 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 ConceptRelational EquivalentProblem
ObjectRow (tuple)Objects have behavior (methods); rows are passive data
ClassTableClass inheritance ≠ table relationships
EncapsulationNo direct equivalentAll data in a row is visible
References (pointers)Foreign keysNavigating references requires JOINs (slower)
Collections (lists, sets)Separate tablesRequires 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.

FeatureWhat It Adds
User-defined types (UDTs)Custom data types beyond built-in ones
Composite attributesNested structures within columns
Methods/functionsBehavior attached to data types
InheritanceTable inheritance (one table extends another)
Array/JSON columnsStore complex structures in a single column

Examples

DatabaseObject-Relational Features
PostgreSQLUser-defined types, table inheritance, arrays, JSONB, custom functions
OracleObject types, VARRAYs, nested tables, methods
SQL ServerCLR 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

FeatureRelationalOOOR (Hybrid)
Data unitRow in tableObjectRow with complex types
Query languageSQLObject query (non-standard)SQL + extensions
RelationshipsForeign keysPointers/OIDsBoth
InheritanceNoYesTable inheritance
ACIDYesLimitedYes
ScalabilityExcellentPoorExcellent
Complex dataPoorGoodGood

Why the OO Model Didn’t Win

ReasonExplanation
No standard query languageEvery OODBMS had its own API
Poor performance at scaleObject navigation is slower than set-based SQL
Lock-inHard to migrate between OODBMS vendors
Relational is “good enough”ORMs bridge the gap for most apps
Web-scale demands consistencyRelational 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.

My Private Notes

Notes are auto-saved locally to this device.