Dofactory.com
Dofactory.com
 Back to list
Views:   5.8K
Replies:  1
Archived

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
Dennis Tucker, Feb 16, 2015
Reply 1
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




Jack Poorte, Mar 02, 2015
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.