Home  /  Questions  /  Question



60   95.3
Sep 04, 2010


Complex Business Rule - Custom Validation sample

Hi,

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.

Regards,

Hemal Shastri



830   99.9
Sep 06, 2010
Hemal:

The logic for custom/complex business rules are placed in the Service Layer. 
If you are using the Patterns in Action application, then you would add these in the ActionService.cs file.

As an example: if you had a complex rule that would determine whether the current user can see specific orders, you would place that logic in the GetOrders method.  Since these rules are complex it is probably best to factor these out in a special private method, such as, bool IsAllowedToSeeOrder(userId, orderId).  If this method return false, then they cannot see the order.

I hope this gets you going.
 2 comments
 
Thanks a lot Dan..This is really very helpful for me.... --- Hemal Shastri  Sep 06, 2010
 
That doesn't seem right because now we have business logic in 2 places. Couldn't we do the same thing in the business layer? --- Dennis Tucker  May 22, 2012