For a new programmer, is it ok/recommended, or not?
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:
- OO is often a good way to develop software
- SQL DBs are often a good way to store data
- Designing the mapping from SQL to OO may be non-trivial
If not, is the alternative to an OO program a procedural program?
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 ...
class Animal
{
int id;
string name;
abstract void eat();
abstract void breed();
}
class Dog : Animal
{
bool pedigree;
override void eat() {...}
override void breed() {...}
}
class Bird : Animal
{
bool carnivore;
int numberOfEggs;
void fly() {...}
override void eat() {...}
override void breed() {...}
}
... it isn't obvious whether to store this data using 2 SQL tables, or 3. Whereas if you take the subclassing away:
class Dog
{
int id;
string name;
bool pedigree;
void eat() {...}
void breed() {...}
}
class Bird
{
int id;
string name;
bool carnivore;
int numberOfEggs;
void fly() {...}
void eat() {...}
void breed() {...}
}
... then it's easier/more obvious/more 1-to-1/more accurate to model this data using exactly two tables.
Also I don't understand Object-relational impedance mismatch
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:
"Manual mapping. Developers simply
accept that it's not such a hard
problem to solve manually after all,
and write straight relational-access
code to return relations to the
language, access the tuples, and
populate objects as necessary."
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.