Search code examples
databaselanguage-agnosticdesign-patterns

Design Patterns for Interfacing with Relational Databases?


Does anyone know of any design patterns for interfacing with relational databases? For instance, is it better to have SQL inline in your methods, or instantiate a SQL object where you pass data in and it builds the SQL statements? Do you have a static method to return the connection string and each method just gets that string and connects to the DB, performs its action, then disconnects as needed or do you have other structures that are in charge of connecting, executing, disconnecting, etc?

In otherwords, assuming the database already exists, what is the best way for OO applications to interact with it?

Thanks for any help.


Solution

  • I recommend the book Patterns of Enterprise Application Architecture by Martin Fowler for a thorough review of the most common answers to these questions.