OK, so let start from the beginning. For instance, I’m developing some big project. It isn’t a secret for all of us that such projects contains a lot of common logic. Say, for example, that some online shop order must have some items and sum of prices of all items must be exactly 1000. So, I implement this logic in MVC3 web application and do validation on order. If there are issues it will tell user about issues and ask him to repost the form.
But project has another important part. It’s DB. Here I can also wrap this validation logic in some stored procedure and add orders only through this proc to be sure that there is no inconsistencies. (Or should I use checks on table to be sure?)
Here’s the stuck I run. It is necessary to dublicate logic in two places to get data integrity. Of course, I may store validation logic only on DB side. But I doubt it will decrease application performance.
I’m sure more experienced guys has a complete and elegant solution for this question.
So, how can I implement logic only in one place?
Simple answer, not to everyone’s liking
Edit, about the latter part
Not all logic needs to be implemented in the database: only logic that will be common to several client code bases. Or you can funnel these common requests through a separate tier/service that deals with it.
Note, some business logic is based on aggregations or cross-table or whole-table checks that simply are best done in the database