Re: Decouple SQL queries from class in OOP design
- From: Robert C. Martin <unclebob@xxxxxxxxxxxxxxxx>
- Date: Thu, 17 Nov 2005 19:30:26 -0600
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).
>But I am not sure
>what the best way is to decouple them. The method that I am using right
>now is to create a hash to store all the SQL statements and prepare
>them in the main program, then I will pass this hash as a variable to
>all the classes that are going to use it. I am not sure whether there
>is any better design. Thanks in advance!
I would not do this. Rather I would create a set classes that know
how to query the database and convert the data into the form that the
business rules would like to see it.
-----
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
.
- Follow-Ups:
- Re: Decouple SQL queries from class in OOP design
- From: Mikito Harakiri
- Re: Decouple SQL queries from class in OOP design
- References:
- Decouple SQL queries from class in OOP design
- From: Hongyu
- Decouple SQL queries from class in OOP design
- Prev by Date: Re: Decouple SQL queries from class in OOP design
- 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
|