Re: Mixing OO and DB
Date: Tue, 4 Mar 2008 23:56:49 -0600
Message-ID: <200803042356491393-unclebob_at_objectmentorcom>
On 2008-03-04 14:01:56 -0600, Marshall <marshall.spight_at_gmail.com> said:
> On Mar 4, 10:10 am, Gene Wirchenko <ge..._at_ocis.net> wrote:
>> Robert Martin <uncle..._at_objectmentor.com> wrote:
>>
>>> get_accountant("Bob");
>>> or
>>> find_by_name_and_department("Bob", "Accounting");
>>
>>> I'm sure you can think of some others that would read nicer than the SQL.
>>
>> Now throw another column into the mix. How many methods are you
>> going to end up with? What will you have gained?
>
> Nice point.
>
> Now let's consider what all the combinations are. If we have
> a single table with ten columns, then we have 1024 possible
> column lists, so if we want a class for each such we need
> a thousand classes.
Two points.
- We don't need a class for each, we need a method for each.
- We never need more methods than SQL statements.
So unless you have 1024 SQL statements in your application code, you aren't going to need 1024 methods.
If you only have five different ways to query, you will only need five different methods.
Of course since it's not uncommon for the same kind of query to appear more than once in the code, you'll probably need even fewer methods than you have SQL statements.
-- Robert C. Martin (Uncle Bob) | email: unclebob_at_objectmentor.com Object Mentor Inc. | blog: www.butunclebob.com The Agile Transition Experts | web: www.objectmentor.com 800-338-6716 |Received on Wed Mar 05 2008 - 06:56:49 CET