Is ORM a problem specific to object oriented programming?

Object-relational mapping, ORM is a problem that must be solved in all applications implemented in an object-oriented programming language, and use a relational database.

But isn’t the problem the same if you use structures to map relational databases in C? And tuples / records in a functional programming language? Or something is missing for me, as I have not written a database application in C or in a functional language.

+6
oop functional-programming orm procedural-programming paradigms
source share
4 answers

Well, yes and no .

What you are talking about is called the mismatch of the object-relational impedance , that is, the problem of transferring data between the object-oriented model and the Entity-Relationship model. The difficulty is associated with the different ways of structuring and storing information in two models, where OO is hierarchical and ER is tabular.

Object-relational mapping is a method that attempts to solve the problem of mismatch between object-relational impedance.

The term object-relational impedance mismatch is specific to Object-Oriented and Entity-Relationship . However, the word “impedance” means resistance or difficulty, so the term “impedance mismatch” could potentially be used to express a common mapping problem between two incompatible data systems / types.

+6
source share

Anecdotally, at least, this “impedance mismatch” is apparently characteristic of situations when a person wants to push relations to the idiom of an object.

In C, most database APIs tend to reveal sets of results as multidimensional arrays rather than structures. Therefore, one of them simply gets access to the data in the same format as in the table (s) in the database, which is not essential that it now exists as a local copy of the data, and not "in the database".

Most RDBMS functional libraries expose database rows as record types that are almost perfect for database rows. In this situation, there is no “impedance mismatch”.

The Wikipedia article on this issue seems to reflect on some of the reasons why the object's paradigm is particularly susceptible to this mismatch.

I am convinced that it essentially depends on the fact that you always build a secondary representation of the data (that is, overlay "objects"). In most imperative or (non-object) functional languages, it is less likely that you will create such a large, semantically irrelevant secondary representation of your data. If someone is going to create a secondary representation in this world, he is likely to be an abstraction of some kind. This is consistent with the basic (unfounded) belief that the OOP paradigm is basically the notorious hammer that makes every problem look like a nail.

+6
source share

The main problems in ORM are not handling simple functions, such as matching the column "x" with the field "x". This can be done with a few tricks (macros, gen code, reflection, etc.).

The problem is how to handle OOP functions such as inheritance, composition, links, uniqueness of objects, interfaces, etc. Inheritance is a bitch in this sense, since its naive implementation as multiple tables is not optimal.

+3
source share

You have 2 resistance mismatches.

  • Writes objects.
  • Your SQL query language.

While the first impedance mismatch may not work for all languages ​​other than OOP, the second is appearing in all languages ​​and can be resolved using DSL as shown here

+3
source share

All Articles