Content deleted Content added
m Reverted edits by 88.109.153.77 (talk) (HG) (3.4.12) |
No edit summary |
||
(35 intermediate revisions by 22 users not shown) | |||
Line 1:
{{short description|Set of conceptual and technical difficulties}}
{{More footnotes|date=August 2020}}
'''Object–relational impedance mismatch''' is a set of difficulties going between data in relational data stores and data in ___domain-driven object models. [[relational database management system | Relational Database Management Systems]] (RDBMS) is the standard method for storing data in a dedicated database, while [[Object-oriented programming|object-oriented]] (OO) programming is the default method for business-centric design in programming languages. The problem lies in neither relational databases nor OO programming, but in the conceptual difficulty mapping between the two logic models. Both logical models are differently implementable using database servers, programming languages, design patterns, or other technologies. Issues range from application to enterprise scale, whenever stored relational data is used in ___domain-driven object models, and vice versa. Object-oriented data stores can trade this problem for other implementation difficulties.
The term ''
== Mismatches ==
=== Object-oriented concepts ===
==== Encapsulation ====
[[object (computer science)|Object]] [[Encapsulation (object-oriented programming)|encapsulation]] hides internals. Object properties only show through implemented interfaces. However, many [[object–relational mapping|ORM]]s expose the properties publicly to work with database columns. Metaprogramming ORMs avoid violating encapsulation.
==== Accessibility ====
==== Interface, class, inheritance and polymorphism ====
==== Mapping to relational concepts ====
=== Data type differences ===
=== Structural and integrity differences ===
Objects can comprise other objects or specialize. Relational is unnested, and a relation ([[tuple relational calculus|tuple]]s with the same header) does not fit in OO.
Relational uses [[Declarative programming|declarative]] constraints on scalar types, attributes, relation variables, and/or globally. OO uses exceptions protecting object internals.
=== Manipulative differences ===
=== Transactional differences ===
== Solving impedance mismatch ==
=== Alternative architectures ===
# ''NoSQL''. The mismatch is not between OO and DBMSes. Object-relational impedance mismatch is eponymously only between OO and '''R'''DBMSes. Alternatives like [[NoSQL]] or [[XML database]]s avoid this.
=== Minimization ===▼
# ''Functional-relational mapping''. [[List_comprehension|Comprehensions]] in functional programming languages are isomorphic with relational queries.<ref>{{cite web | url=https://nbviewer.org/github/phelps-sg/python-bigdata/blob/master/src/main/ipynb/relational-python.ipynb | title=Jupyter Notebook Viewer }}</ref> Some functional programming languages implement functional-relational mapping.<ref>{{cite web | url=https://scala-slick.org/doc/stable/introduction.html | title=Introduction · Slick }}</ref> The direct correspondence between comprehensions and queries avoids many of the problems of object-relational mapping.
▲=== Minimization in OO ===
[[Object database]]s (OODBMS) to avoid the mismatch exist but only less successfully than relational databases. OO is a poor basis for schemas.<ref>C. J. Date, Relational Database Writings</ref> Future OO database research involves [[Software transactional memory|transactional memory]].
Another solution layers the ___domain and framework logic. Here, OO maps relational aspects at runtime rather than statically. Frameworks have a tuple class (also named row or entity) and a relation class (a.k.a dataset).
==== Advantages ====
* Straightforward
* Smaller, faster, quicker code{{Citation needed|date=July 2024}}
* Dynamic [[database schema]]
* Namespace and semantic match
* No static typing. Typed accessors mitigate this.
▲* Straightforward paths to build frameworks and automation around transport, presentation, and validation of ___domain data.
* Indirection performance cost
*
▲* Expressive constraint checking
▲* No complex mapping necessary
▲Disadvantages may include:
▲* Inability to natively utilize uniquely OO aspects, such as [[Polymorphism in object-oriented programming|polymorphism]].
=== Compensation ===
== Occurrence ==
Although object-relational impedance mismatches can occur with object-oriented programming in general, a particular area of difficulty is with [[
== Contention ==
=== True RDBMS
=== Constraints and
=== SQL-
Mainstream DBMSes like Oracle and Microsoft SQL Server solve this. OO code (Java and .NET respectively) extend them and are invokeable in SQL as fluently as if built into the DBMS. Reusing library routines across multiple schemas is a supported modern paradigm.
This contention may be moot. RDBMSes are not for modelling. SQL is only lossy when abused for modelling. SQL is for querying, sorting, filtering, and storing big data. OO in the backend encourages bad architecture as business logic should not be in the data tier.
=== Location of
=== Division of
New features change both code and schemas. The schema is the DBA's responsibility. DBAs are responsible for reliability, so they refuse programmers' unnecessary modifications. Staging databases help but merely move the approval to release time. DBAs want to contain changes to code, where defects are less catastrophic.
More collaboration solves this. Schema change decisions should be from business needs. Novel data or performance boosts both modify the schema.
== Philosophical differences ==
Key philosophical differences
* '''Declarative vs. imperative interfaces'''{{snd}} Relational
* '''Schema bound'''{{snd}} Relational limits rows to their entity schemas. OO's inheritance (tree or not) is similar. OO can also add attributes. New and few dynamic database systems unlimit this for relational.
* '''Access rules'''{{snd}}
* '''Relationship between nouns and verbs'''{{snd}} An OO
* '''Object identity'''{{snd}} Two mutable objects with the same state differ. Relational ignores this uniqueness, and must fabricate it with [[candidate key]]s but that is a poor practice unless this identifier exists in the real world. Identity is permanent in relational, but maybe transient in OO.
* '''Normalization'''{{snd}} OO neglects [[Database normalization|
* '''Schema inheritance'''{{snd}} Relational schemas reject OO's hierarchical inheritance. Relational accepts more powerful [[set theory]]. Unpopular non-tree (non-[[Java (language)|Java]]) OO exists, but is harder than relational algebra.
* '''Structure vs. behaviour'''{{snd}} OO
* '''Set vs. graph relationships'''{{snd}}
== See also ==
Line 126 ⟶ 127:
{{DEFAULTSORT:Object-relational impedance mismatch}}
[[Category:Object-oriented programming]]
[[Category:
[[Category:Relational model]]
|