Re: Decouple SQL queries from class in OOP design
- From: Robert C. Martin <unclebob@xxxxxxxxxxxxxxxx>
- Date: Fri, 25 Nov 2005 10:21:16 -0600
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
.
- References:
- Decouple SQL queries from class in OOP design
- From: Hongyu
- Re: Decouple SQL queries from class in OOP design
- From: Robert C . Martin
- Re: Decouple SQL queries from class in OOP design
- From: Mikito Harakiri
- Decouple SQL queries from class in OOP design
- Prev by Date: Re: About Call Graph
- Next by Date: Re: Decouple SQL queries from class in OOP design
- Previous by thread: Re: Decouple SQL queries from class in OOP design
- Next by thread: Re: Decouple SQL queries from class in OOP design
- Index(es):
Relevant Pages
|