It is well established that N-Tier architectures work, especially as a facilitator for all the Service Oriented Architecture Hype (which is well deserved in my opinion). Putting business rules in the database is a bad idea in general (if I had to give a binary response). In fact putting any business rules, except for those that you must for performance reasons in the database is a bad idea (and then I would really want to look at that rule and see why). What makes me take this position after 14 years building global multi-million dollar systems?
Well today, you may confidently think you will always use SQL Server at your shop or even your enterprise. However, some day when you are asked by your new CTO who happens to play golf with the CEO of Sybase to migrate to Sybase on Solaris (the new CTO hates Windows), do you want to spend months changing your code or days? And assuming .NET again if you make the mistake of putting the actual client namespace in your code you will have to change all of those references.. Ugly.
I recently participated on a groundbreaking architectural implementation of an abstract factory pattern for relational databases for .NET. Good software engineering dictates we minimize dependencies and only have them as much as possible to Interfaces and Abstract Classes. Well imaging your database using a classed called (we are in the .NET environment) AdoHelper. This class would have all the database operations you would expect for DataSets, DataReaders, Transactions, etc.
To see this visually go here:
http://www.agilefactor.com/daab3/
Click on the bottom left on ?Class Diagram? to see the high level structure.
AdoHelper is completely abstracted from the underlying concrete child implementations (and it has no knowledge of them as we use reflection to load assemblies ? critical for a good factory implementation). When a database is needed it is retrieved through a 'factory' method that uses reflection to instantiate the SQL Server, Oracle, DB2, or whatever assembly, load it and create an instance. It then sends it back, cast into the base abstract class.
Look at the same URL but click on the ?DAAB3 Sequence of Creation? for a sequence diagram of how this works.
Your entire application (and hopefully in an N-Tiered environment only your business tier is speaking to your Database Tier) it would only have a dependency (think UML Dependency) on the AdoHelper. Not one class in your application has any knowledge of the children of AdoHelper so you are free to support any database you like.
This is exactly what we accomplished. I have used this on many projects with great success, and my firm even offers a class on this technology (and helps companies implement it all over the world). If you write ANSI Standard SQL and keep stored procedures to a minimum, you can have an application that is fairly database Agnostic. A change from SQL Server to Oracle could be done in days.
But what about feature X? Or Feature Y that are database specific?
This environment is meant to be extended. A good example would be retrieving data as XML. Most major vendors are doing this but not all. You can still have the same method name, yet in the implementation serialize the DataSet (or DataTable or DataReader) to XML. The caller doesn't know that the database didn't do it natively.
For example, the SQL Server concrete class does exactly that. It sends back SQL using the SQL Syntax SQL Server supports for retrieving XML. But what about an older version of Sybase? No problem. You can implement the same functionality, only this time returning the DataSet as XML.
So where can you find this framework? Go here:
http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=c20d12b0-af52-402b-9b7c-aaeb21d1f431
There are equivalent environments for J2EE developers. Speaking as a software engineering leader who has to write products that are database agnostic, anything but the most trivial of applications can benefit from a framework such as this. And I do not think Stored Procedures are bad. I just HATE multiple code bases and every time we have one and we add a feature, we have to maintain a version for all the major vendors and it is a real pain.
Also..In many cases just use prepared statements! You gain much of the benefit and they are one of the most underutilized techniques I can think of (that and doing decent object-oriented design). Sorry I couldn?t resist.. Read the Standish group statistics, The custom software industry is in incredibly horrible shape and my firm and many like mine are out to fix it.
Kind Regards,
Damon Carr, Chief Technologist and CEO
agilefactor
http://www.agilefactor.com/