In trying to understand the correlation between program objects and data in tables (here:OO program and SQL database), which I still don’t really understand, a strong difference of opinion was revealed over whether it’s ok to use a SQL db to store data for an OO program.
-
For a new programmer, is it ok/recommended, or not?
-
If not, is the alternative to an OO program a procedural program?
Also I don’t understand Object-relational impedance mismatch, which is what people mean when they say that it’s “not OK to use an SQL DB to store data for an OO program”: can someone summarize it, or is there a simple example that illustrates it?
That question implies that the system design/components/architecture are chosen/intended to benefit the programmer.
Instead I prefer to choose the design/components/architecture to benefit the system (and the system’s owners, users, and operators), and ensure that the programmers know (which may require some learning or training on their part) what they need in order to develop that system.
The facts are:
Well, maybe, yes: one of the features of OO is subclassing, and subclasses/inheritance is one of the things that’s problematic to model/store in a SQL database.
For example, given a OOD like this …
… it isn’t obvious whether to store this data using 2 SQL tables, or 3. Whereas if you take the subclassing away:
… then it’s easier/more obvious/more 1-to-1/more accurate to model this data using exactly two tables.
Here’s an article that’s longer and more famous than the Wikipedia article; maybe it’s easier to understand: The Vietnam of Computer Science
Note that one of the solutions, which is proposes to the problem, is:
In other words, it’s not such a hard problem in practice. It’s a hard problem in theory, i.e. it’s hard to write a tool which creates the mapping automatically and without your having to think about it; but that’s true of many aspects of programming, not only this one.