Business Logic Question(s)

Hi, I believe this is the right place to post this query. I'll give you some background first.

I have an asp.net application that accesses business objects which in turn accesses a data access layer to read information from a database, pretty standard stuff!  Most of the pages are simple in that the user can either edit the data or they can't so in the business objects there is a base method that returns a bool for whether to disable the controls or not, this works a treat!

The problem lies in the pages that have 2 or more sections that can be disabled depending on certain conditions, so one area may be disabled but another area may be enabeld, so the blanket enable / disable doesn't work here.  At the moment the logic for determining what sections are enabled or disabled is in the code behind file of the asp.net pages that require them.

I suppose my question is, in an ideal world this logic should be in the business layer but I can't see how I would link this to the presentation layer without putting some of the business logic in the code behind page. Does anyone know how this could be accomplished

 

Thanks



Answer this question

Business Logic Question(s)

  • JPNMN

    I don't know that it is really wrong, but how tight does this make the coupling between the business layer and the UI layer. I think that it is more appropriate to put business logic in the UI layer than to have the business layer know about the UI.

    Now if the flags you are creating purely represent the state of the data and can be resused by other components then I would consider them apropriate.

    Those are just my thoughts. Others may have different views.



  • SonalMS

    I agree with Tim

    There is room for presentation logic (take a look at http://codebetter.com/blogs/jeremy.miller/archive/2006/02/01/137457.aspx)

    It seems the presentation logic should deduce what to enable based on the business object state rather than have flags on the business objects that are sepecific to the UI

    Arnon



  • MagicCity33

    I tend to agree with the last couple of posts on this thread. I don't see how the decision to enable/disable controls is business logic This seems more like code that lives in the presentation layer and makes these decisions based on the state or information retrieved within a business object. I would even favor a looser coupling of the view and the model by using some type of controller to retrieve the entities and act on the view according to the state of the model.

    This article does a good job introducing the concept (http://www.c-sharpcorner.com/Code/2003/Feb/MVCDesign.asp) and if you want to dig into it deeper you'll find some content in the patterns and practices stuff and other design pattern books.



  • Piotr Smolanski

    I think I have figured it out, the sections of controls are all related and this logic should be in the business object in question, a couple of bollean flags could be set in the business object to let the presentation layer know what sections are to be enabled or disabled.

    This way the presentation layer doesn't have the logic for which section should be enabled, the business layer will have this logic and will expose the outcome to the presentation layer so that it knows what to enable / disable.

    Fell free to tell me i'm wrong, or that there is a better way to do it!


  • Craig Lichtenstein - MSFT

    I think this code belongs in the presentation layer as the presentaltion layer pertains to UI information. Whether a control is enabled or disabled is certainly apropriate to store in the UI layer.
  • Business Logic Question(s)