Business Object Best Practices

Business Object Best Practices

Old forum URL: forums.lhotka.net/forums/t/3180.aspx


dantruj posted on Thursday, July 12, 2007

I apologize if this is not the correct forum (csla) to discuss basic business objects, but I have searched the web to find some answers to my question and have not been able to.  That said, here is my question.

The UI has a list box that should display persons who's records are active = true.  As the business developer I have provided a businesslist object which returns a list of persons filtered by Active = true.  In the UI the record is saved with the person (who is currently active) selected from the list box.  The problem arises when in the UI through some administration screen the Person is made inactive (left the company lets say).  Now through the UI we go back to the screen where the list box and where the person (who is now inactive) was set.  Since the list box only shows active persons, and the list.SelectedValue is set to the inactive person an error will be thrown. 

Here is my question:

The UI people say that I should provide from the business layer a PV that returns a list of active persons and the inactive person item.  They want  a method which accepts a parameter to pass in the inactive person's ID so that I can append to the list.  I disagree with this approach, I believe the business object should not change anything and return the list of active persons.  It is up to the UI to know that this record is inactive and append to the listbox items list.  The only thing that I feel the Business layer should do is throw an error if the record is being saved with a person who is no longer active. 

What do you all think?

 

RockfordLhotka replied on Thursday, July 12, 2007

This is a common issue, and is relatively difficult to solve in a distributed setting (at least if you value scalability and reliability).

Technically, of course, it is virtually impossible to solve due to a concurrency issue. In other words, the potential for an exception is always there. Consider the case where user A is editing the person, while user B makes them inactive. This is after user A is past selecting the person from your filtered list...

On a single machine it is pretty easy to have the list know it is invalid when the admin screen is used, because you can use a simple observer pattern with an event for notification. This sounds like what you are being asked to do, and it really isn't that hard (though it should be done through events, not through a hard-coded method call).

Across a network, however, it is quite difficult to do event notifications in a way that scales and is reliable... Some people do tackle this problem, but most people find it too expensive to solve and choose to live with the occasional exception.

In the end, it is a solvable problem, but it is a business decision as to whether the short and long term costs of solving it can be justified by the business value of having a better user experience.

ajj3085 replied on Thursday, July 12, 2007

dantruj:
The UI people say that I should provide from the business layer a PV that returns a list of active persons and the inactive person item.  They want  a method which accepts a parameter to pass in the inactive person's ID so that I can append to the list.  I disagree with this approach, I believe the business object should not change anything and return the list of active persons.  It is up to the UI to know that this record is inactive and append to the listbox items list.  The only thing that I feel the Business layer should do is throw an error if the record is being saved with a person who is no longer active.


I this is a UI issue.  The UI should build the merged list, and the business layer should provide a means to do so.  So you may have a Person list, with an inactive flag.  The BO should ONLY be valid if the person selected has its Active flag set to true.  You'll need a way to get an inactive person though, likely via the person's id.

Your BO must also do as Rocky says, and check just before updating the record that the person refernce is still an active person.  I believe if you start a transaction, select the person's most current data and check it, that you will lock the person record until your transaction completes. 

HTH
Andy

Copyright (c) Marimer LLC