Course contentsShow
← Software Engineering
Lesson 929 of 1,93329. Object-Relational MappingFree lesson

Structural Differences: Objects vs. Tables

How object hierarchies, composition, and inheritance differ from flat relational table structures.

Structural Differences: Objects vs. Tables

You'll learn how object-oriented design patterns map awkwardly onto flat relational tables.

The Core Structural Mismatch

Object-oriented programming embraces hierarchies, composition, and inheritance—rich structures where objects nest within each other and share behaviors through class relationships. Relational databases, however, store data in flat tables with rows and columns, where relationships are expressed through foreign keys, not nesting.

Three Key Structural Conflicts

Inheritance

In OOP, a Manager class might inherit from an Employee class, sharing fields and behaviors. In a database, you must choose: one table with a type discriminator column? Separate tables? A shared base table with joined sub-tables? None feel natural.

Composition

An Order object might contain an Address object nested directly within it. Databases don't nest—you either flatten the address fields into the order table (order_street, order_city) or create a separate addresses table and link via foreign key, breaking the natural containment.

Object Graphs

Objects form networks: an Order references a Customer, which references multiple Orders, which reference Products. These bidirectional relationships and complex graphs must be flattened into unidirectional foreign key references across multiple tables.

The Analogy

Think of objects as Russian nesting dolls (матрёшка)—each containing others in a hierarchy. Relational tables are like spreadsheets laid side-by-side, where you write down IDs to reference rows in other sheets. Translating between these requires careful mapping strategy.

Key Takeaway: Objects naturally express hierarchies and composition through nesting and inheritance, while relational tables are fundamentally flat structures that express relationships through foreign keys—requiring explicit translation patterns to bridge this structural gap.