Re: Mixing OO and DB

From: Robert Martin <>
Date: Thu, 6 Mar 2008 01:21:44 -0600
Message-ID: <2008030601214447408-unclebob_at_objectmentorcom>

On 2008-03-04 18:01:51 -0600, Gene Wirchenko <> said:

> Robert Martin <> wrote:

>> On 2008-03-04 00:25:43 -0600, topmind <> said:

> [snip]
>>> Um, like what if there are zero Bob's or 200 Bob's in the actual
>>> system? Are you gonna arbitrarily pick one?
>> Don't be silly.  find("Bob") will either return the object for "Bob" or
>> it will return nothing.  You would only use this method if you knew
>> that there could be no more than one "Bob".

> So if there is more than one "Bob", the method will return
> nothing?

If there is more than one bob, the function will throw an exception.

>> If there could be more than one "Bob", then you would use a function
>> like: find_all("Bob") which would return a list of all the matching
>> objects.

> The supposedly more complicated SQL uses the same query for each.
> Then, you check how many rows were returned. Writing two methods is
> simpler? Ah, no.

Pretending that 1 is plural is simpler? Sometimes you want to *assert* that there is just one.

Robert C. Martin (Uncle Bob)  | email:
Object Mentor Inc.            | blog:
The Agile Transition Experts  | web:
800-338-6716                  |
Received on Thu Mar 06 2008 - 08:21:44 CET

Original text of this message