Re: Mixing OO and DB
Date: Thu, 6 Mar 2008 13:54:30 -0800 (PST)
Robert Martin wrote:
> On 2008-03-02 13:28:28 -0600, frebe <frebe73_at_gmail.com> said:
> > On 2 Mar, 20:01, Robert Martin <uncle..._at_objectmentor.com> wrote:
> >>>> � Employee e = Employee.find("Bob"):
> >>>> � DataRow e = exec("Select * from EmployeeTable where name = 'Bob';);
> >>> Why is the first line better than the last line?
> >> It's smaller, more communicative, and can be polymorphically deployed.
> > Both are one-liners.
> True, but most forms of the top line will remain one-liners even when
> the SQL grows to many lines.
If such grows too big, I too may "functify" it, or at least portions of it.
[snipped arguments addressed elsewhere]
> >> All we are doing is giving each query a name. �That name
> >> is the name of the method that is implemented by the SQL. �This allows
> >> the programmer to commnicate the *intent* of the query, rather than
> >> it's implementation.
> > What stops you from creating views when suitable?
Actually, the DBA sometimes does, but view access rights is another story.
> >>> What is the benefit with hiding SQL from the bulk of the application?
> >> You can provide test implementations that don't use the database, but
> >> allow you to quickly test business rules.
> > If the business rules (eligible_for_retirement) is in the database,
> > the test would be pretty useless.
> The business rule is not the query. The business rule is what is done
> with the results of the query. For example, I want to test that I can
> send email to all the eligible employees, and format that email nicely
> with their name, employee number, years of service, etc. The query is
> irrelevant to the job of creating and sending the emails.
And again, one could have a DB of test cases to make sure our filtering works as intended. Otherwise, we might send a very fancy and shiney TERMINATION notice to the WRONG employees, and they'd have to go do something new, such as become OO book authors :-)
> Robert C. Martin (Uncle Bob)��| email: unclebob_at_objectmentor.com
> Object Mentor Inc.� � � � � ��| blog:��www.butunclebob.com
-T- Received on Thu Mar 06 2008 - 22:54:30 CET