Re: Decouple SQL queries from class in OOP design



"Hongyu" <forward@xxxxxxxxxx> writes:
> 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. But I am not
> sure what the best way is to decouple them.

A "good" OO design will typically focus more on behavior than on
state. Before deciding on a persistence solution, you need the
answers to a number of questions, including:

- How much information do you need to persist?
- What are your performance requirements?
- Do you control the database schema or does the database support
many systems across the enterprise?
- How do you see the persistence requirements changing over the
anticipated lifetime of your system?

> 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.

Have you looked at any existing OO-RDBMS mapping tools
appropriate for your combination of implementation language(s), OS,
and DBMS? Even if your requirements don't currently justify the cost
and expense of such a solution, you will learn how the problem has
been solved by others and can avoid reinventing the wheel.

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc. | The experts in large scale distributed OO
| systems design and implementation.
pjm@xxxxxxx | (C++, Java, Common Lisp, Jini, CORBA, UML)
.



Relevant Pages

  • Re: Having difficulty refactoring a DB application
    ... I don't know about any persistence mechanism that is less ... rest of the applications. ... > abstraction for various subsystems. ... abstraction in the database schema. ...
    (comp.object)
  • Re: Design Question
    ... When you add a column to your database schema you ... data itself is not related to the persistence. ... private String recordName; ...
    (comp.lang.java.programmer)