Complex Business Rule - Custom Validation sample

50   50
Jun 20, 2012

I recently purchased Design Pattern Framework 4.0.

In the document it is mentioned like
Here is an example of a more complex rule. There may be a rule that states that customers are ranked according to their recent order history. Customers with 10 or more orders over the last 3 months receive gold status, customers with 5 to 10 orders receive silver status, and customers with fewer than 5 orders are given bronze status. These statuses can be used to determine the relative priority treatment they receive when calling a 1-800 customer support number. When an order is placed, the rule in the business object re-evaluates the customer‟s ranking. These kind of rules require (in most cases) custom validation code.

Another is
In a more complex application you may have interdependent business rules encoded outside these objects (for example, if the bank account is over $5000 and more than 3 transactions have taken place in the last month, and the account holder‟s age is > 35 and is on the same job for more than 2 years, then accept the application).

Can someone guide me where and how to write above two validation in existing Design Pattern Framework 4.0.


76   96.2
Jul 12, 2012
These rules are encoded in the Service Layer.

In the first example, when saving the order, you 1) save the order, and then 2) evaluate all the rules and update the user's record. These actions should be bracketed by a Transaction, which is also done in the Service Layer.

Second example also takes place in the Service Layer. When requesting approval for a mortgage you have a method on the Service Layer that evaluates all the conditions and renders a final answer back to the user.

Hope this helps.
So, a complex business rule should be in the Service Layer? If that is the case what is the purpose of the Business Layer? Having rules throughout multiple layers seems like it could become a maintenance nightmare. Thanks Dennis --- Dennis Tucker  Aug 06, 2012
Greetings, I am facing the same dilemma! Where toput the business rules without a lot of repetition? Thanks, Everardo --- Everardo Cunha  Sep 19, 2012
I was under the impression that all Business rules was to stay in the business layer. You can annotate your objects with small business rules to get instant results which makes for a better user experience but you should also put those same rules in the business layer along with the complicated rules. Service layer is to only make the more complicated stuff below easier. This way you are not having rules across all layers. Thanks --- Dennis Tucker  Sep 24, 2012