Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you keep your business rules DRY?

In the perfect application every business rule would exist only once.

I work for a shop that enforces business rules in as much as possible in the database. In many cases to achieve a better user experience we're performing identical validations on the client side. Not very DRY. Being a SPOT purist, I hate this.

On the other end of the spectrum, some shops create dumb databases (the Rails community leans in this direction) and relegate the business logic to a separate tier. But even with this tack, some validation logic ends up repeated client side.

To further complicate the matter, I understand why the database should be treated as a fortress and so I agree that validations be enforced/repeated at the database.

Trying to enforce validations in one spot isn't easy in light of conflicting concerns -- stay DRY, keep the database a fortress, and provide a good user experience. I have some idea for overcoming this issue, but I imagine there are better.

Can we balance these conflicting concerns in a DRY manner?

like image 991
Mario Avatar asked Mar 31 '10 20:03

Mario


People also ask

What is the importance of business rules?

Business rules are now accepted as an underlying requirement of most organizations. They are often used to help prepare system flows or procedural flow charts that outline how a business will operate. When business rules are made right, they provide efficiency, consistency, predictability, and benefits.


1 Answers

Anyone who doesn't enforce the required business rules in the database where they belong is going to have bad data, simple as that. Data integrity is the job of the database. Databases are affected by many more sources than the application and to put required rules in the application only is short-sighted. If you do this you will get bad data from imports, from other applications when they connect, from ad hoc queries to fix large amounts of data (think increasing all the prices by 10%), etc. It is foolish in the extreme to enforce rules only through an application. But then again, I'm the person who has to fix the bad data that gets into poorly designed databases where application developers think they should do stuff only in the application.

The data will live on long past the application in many cases. You lose the rules when this happens as well.

like image 85
HLGEM Avatar answered Oct 13 '22 18:10

HLGEM