Re: Decouple SQL queries from class in OOP design



On 18 Nov 2005 16:43:48 -0800, "Mikito Harakiri"
<mikharakiri_nospaum@xxxxxxxxx> wrote:

>Robert C. Martin wrote:
>> On 9 Nov 2005 17:35:50 -0800, "Hongyu" <forward@xxxxxxxxxx> wrote:
>>
>> >To my knowledge, in OOP design it's not good to mix SQL queries with
>> >application codes in classes, because it limits the usability of the
>> >classes and bound them to the local database schema.
>>
>> Indeed, it is not good to mix SQL with business rules in *any*
>> paradigm. You'd like your business rules to know nothing of SQL.
>> You'd also like your business rules to know nothing of the relational
>> schema. The business rules want to use a convenient set of data
>> structures (or objects).
>
>Cool. When I forget my badge and show
>up at the front door and give them my employee ID, it is sure nice not
>to have an
>EMP table and query it directly, but send a message to each and every
>DEPT
>instance to ask "does emp 1234 work for you?"

Which is, of course, NOT what you would do. A good OO program does
not ignore the fact that a database exists. What it tries to ignore
are the details of the interface; in particular the schema, the API,
and the query language (SQL).

In the case you cited, the program would send a message to a query
object asking for employee# 1234. That query object would then
generate the appropriate SQL, and use the database API appropriately.

>This funny interface separation idea is one of the reasons why data
>mangement folks call OOP crowd incompetent.

Which is an indication of their own ignorance of OO. OO is not ANTI
database. OO design is about decoupling, not about de-USING. OO
designers don't avoid using a database, but they do avoid letting the
knowledge of the details permeate the business rules.


-----
Robert C. Martin (Uncle Bob) | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc. | blog: www.butunclebob.com
The Agile Transition Experts | web: www.objectmentor.com
800-338-6716


"The aim of science is not to open the door to infinite wisdom,
but to set a limit to infinite error."
-- Bertolt Brecht, Life of Galileo
.



Relevant Pages

  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: complex filter and calculations in access
    ... switch to SQL view. ... query by switching to datasheet view, ... of your database using the from address in this post. ... pre-op infections yes/no ...
    (microsoft.public.access.queries)
  • Re: A little more meat this week
    ... implementation with a query processor capable of returning a result set ... then we can call it a result bag (SQL ... I'm looking at the data model and not database tools at this ... for a s/w developer and a s/w developer simplifies for the end user). ...
    (comp.databases.pick)
  • Re: complex filter and calculations in access
    ... when using a subquery on the same table as the main query, ... switch to SQL view. ... of your database using the from address in this post. ...
    (microsoft.public.access.queries)
  • Re: A little more meat this week
    ... said data includes lists." ... implementation with a query processor capable of returning a result set ... then we can call it a result bag (SQL ... I'm looking at the data model and not database tools at this ...
    (comp.databases.pick)