Home  /  Questions  /  Question



108   96.7
Feb 16, 2015


Business Layer

There does not seem to be a way to implement real world business decisions. This design is great for easy data validation but not actual business decisions. What is I wanted to add that a customer gets a 10% discount who has been a member for 2 years? That is a business decision that should be made in the business layer. 

Thanks
Dennis



508   99.9
Mar 02, 2015
Dennis: 

Indeed, the lines between the different layers can become fuzzy. 

In its simplest form, the business layer has just business objects. 
If you need to apply more complex business rules, you can write this in one of these places:  

1) in the controller action method (or code behind), or
2) in a separate service layer if the rule needs to be reusable. 

To go back to your example you gather all the information in a postback action method and determine if the discount applies. If so, save the appropriate information back to the database (one or more objects/tables). If not return an error message to the user.

Alternatively, you can write an ApplyDiscount method in a Service layer (a class named Service) and do the work there.  
Call this method from the controller's action method (or code behind).  This method is then callable from other places as well.

Choose whatever approach is best for you.  

Hope this helps.

Jack




 1 comment
 
thank you for getting back to me. So, what is the purpose of the business layer in this example? The rules that can be applied in this example seem like more of data validation than business rules. --- Dennis Tucker  Mar 03, 2015