Re: Mixing OO and DB

From: Robert Martin <>
Date: Sun, 2 Mar 2008 12:47:41 -0600
Message-ID: <2008030212474116807-unclebob_at_objectmentorcom>

On 2008-02-28 10:36:03 -0600, topmind <> said:


>> Of course we can implement other kinds of 'find' methods.
>> find_by_date, find_by_salary, etc, etc. Every different query we use
>> on a regular basis, we can create a verb for in our DSL. That verb is
>> a function call of some kind.
> Such only makes sense if you do the same kind of query in *multiple*
> spots.  One-usage wrappers are a waste of code in my opinion and just
> creates tedious red-tape accessor clutter.

Not if they are explanatory. Employee.find("Bob") is a lot easier to understand than Select * from Employee_Table where Name = 'Bob'; In any case, once you have the method, you can polymorphically replace it with test methods etc.

>> So we have not lost the power of the flexible query language. We still
>> have it, and we still use it. But we also hide it from the bulk of the
>> application.
>> That allows us to create a polymorphic API below which we can swap out
>> different database implementations, or even stubs and dummies .
> No it wont.

Of course it does. If you have a suite of methods through which you make all your queries, you can polymorphically replace the implementations of those methods.

> Plus, most apps don't switch database vendors.

True, but most apps need to be tested, and the testing independently of the DB can be a significant advantage.

> OOP here is a solution looking for a problem.

Not at all. The problem is very simple. Run 10,000 business rule tests through your application in under a minute. Doing this with the datbase in place is a lot harder than polymorphically replacing the database.

Robert C. Martin (Uncle Bob)  | email:
Object Mentor Inc.            | blog:
The Agile Transition Experts  | web:
800-338-6716                  |
Received on Sun Mar 02 2008 - 19:47:41 CET

Original text of this message