none
Need Suggestion | Business Layer RRS feed

  • Question

  •  Hello All, 

     I am working in a project which uses 3 layer architecture ( DAL, Business layer and UI ). I see  that business layer is just a wrapper which   make a call to dal and send the same data . Then  why this is called busines  layer. 

     Can some one provide suggestions/ answer for the below questions ? 

     1. What is business layer ? what should it contain , Need an example 

     2. Can data access layer directly send business objects or it should always send data table etc      and in business layer we need to convert them to business entity and send it to ui ? 

     3. Could be great if can some  one provide me pointers to learn the same 

    Regards,

    Rajesh

    Saturday, July 21, 2012 5:12 AM

All replies

  • Business layer contains logic that reflects business scenarios.

    For example, if it is said that you should apply 10% interest on savings account and 5% on checking account, this is a business scenario. 

    1. Programmer's approach is to use statement if(account == savingsAccount). This logic will then go into business layer. Business layer is not just a wrapper, but holds business logic. All business scenarios should be reflected in business layer.

    2. DAL responsibility is to get the data for executing business logic. DAL can send business objects directly, but you must be absolutely sure that in future your data table will not change. Even if it changes your client should not be affected. In that case usually you need to touch lot of code to fix.

    DAL programmatic responsibility is mainly to convert table records to .NET objects, or reverse. 

    3. http://www.dotnetfunda.com/articles/article18.aspx

    Monday, July 23, 2012 5:32 AM
  • Hi 

    Usually there will be minimum three logical layers we can see in many application which are designed to be flexible and scalable. As per your question the business objects are simple wrappers then no need for a intermediate layers, be sure there is no business logic involves at all.

    To go with a simple example consider calculate the sum of mark of a student.

    Assume if you have this logic in the DAL class and suppose there is a change in data access logic. Let us say it is decided to move from ADO.NET to LINQ.  Don't you rewrite your sum method. Not only change in data access logic, but layers give abstraction, DAL abstract data structure changes which the business object unaware of. 

    The key is the degree of abstraction required and the agreement between the two layers. When disagreement goes high separation is a concern, Though separation given more flexibility, but when disagreement goes high it apply pressure upon one or the other layer remarkably with a performance overhead. 

    It is been said theoretically if the business layer and DAL has 100% agreement no separation requires or else I would suggest a business layer. And don't go only with flexibility, but keep an eye on the disagreement (in view of performance)  between the layers which needs to be re-factored for both of them to go along with.  100% agreement and 100% flexibility is just theoretical. Trade off is an architecture decision.

    Good Luck! 

    Monday, July 23, 2012 7:12 PM
  • For me it looks like MVC (C#) pattern:

    DAL layer (ObserverClass): has data and know how to manipulate with data (for example: get, set, change)

    Business layer (MediatorClass): has rules how to process data (for example: increment value of data)

    UI layer (ViewClass): can show data, get buttons clicks etc. (for example: can show value of data, have "IncrementData" button)

    Scenario:

    1. Startup:
    MediatorClass get in constructor ObserverClass and ViewClass objects
    MediatorClass get data from ObserverClass object and send it to  ViewClass object
    MediatorClass subscribe to "IncrementData" button click event

    2. When some one  click on "IncrementData" button:
    ViewClass generate event
    MediatorClass get event.
    MediatorClass  increments value of data and send result to ObserverClass object
    MediatorClass  get changed data from ObserverClass object
    MediatorClass  set new value to ViewClass 

    IMHO

    Thursday, August 2, 2012 8:27 AM