Prompting user during business method execution

Prompting user during business method execution

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


triplea posted on Thursday, June 19, 2008

I an object diagram that looks roughly like this:

Customer (BusinessBase)
|
|--------> ProductList (BusinesListBase) ---> Product (BusinessBase)
|--------> SystemList (BusinesListBase) ---> System (BusinessBase)

The idea is that when a Product is added/removed from ProductList, some logic kicks off that either adds or removes a System from SystemList. That works fine but I would like (specially in the case of removing a Product) to prompt the user with an "Are you sure?" message. The problem is that Product-System relationship is not 1-1 so removing a Product doesnt necessarily mean that a system needs to be removed, only under certain conditions.

Initially I thought I would raise an event when my logic detected that a system needs to be removed. But that doesn't really work so I am a bit baffled... Any ideas on how this should be tackled?

KKoteles replied on Thursday, June 19, 2008

triplea,

Sorry I don't have a lot of time right now to work out a better answer; however, it sounds like you want to have one object subscribe to an event from another.  I almost had a similar need a while back - and I found this in Rocky's blog:  http://www.lhotka.net/weblog/IAmWorkingOnMyUsingCSLANET30EbookAndWroteSomeContentThatIDontThinkImGoingToUseInTheBook.aspx .

Hopefully this is either close to what you are looking for - or at least gives you some ideas.

Ken

triplea replied on Friday, June 20, 2008

Thanks Ken but that's not exactly what I am looking for :-)

The problem is that the UI needs to be notified and "intercept" the flow of a business rule. I guess it makes sense that this wouldn't be possible but the only workaround in my use case that I could find is:

This works but I dont like it since the UI is supposed to know that a system will be removed. Too much responsibility for the UI I find!

Fintanv replied on Friday, June 20, 2008

I respectfully disagree.  I think that this is exactly the sort of responsibility that the UI should have.  It is soliciting input from the user to make a decision (hence "UI" Wink [;)]).  Putting some sort of method/property on your business object that will let the UI query it to see if the dialog should be displayed, preserves your business logic encapsulation. 

Sometimes there is no perfect solution, you simply go with the "least worst".

All the best,

Fintan

triplea replied on Friday, June 20, 2008

Disagreeing if absolutely fine :-) You are quite right with your UI definition but (and there is always a but) in my use case things are slightly different. By performing 1 action (removing a Product) another action may or may not be triggered (from within the BL of course) which the UI cannot determine unless it queries the object. Its the fact that the UI developer should know that to query the object that I dont like, not the fact that this method/property should be there in the first place. So yet again you were right that the "least worst" approach is the only way sometimes!

ajj3085 replied on Friday, June 20, 2008

Well, the UI developer would need to do SOMETHING to display the prompt, right?  If you don't want them to have to "know" they need to ask some object to display the prompt, then you can just have the prompt always display.  "Warning, this action may remove a system as well."  Also at some point it's expected that the user knows the use case and work flow as well.. so perhaps this is also partly a training issue.

SomeGuy replied on Friday, June 20, 2008

Rather than trying to intercept the business logic, you could raise an event after the Product and System were removed and display a message stating what happened. The user would then have the option to cancel their edits or save the object.

 

Dawn replied on Saturday, June 21, 2008

You can override ProductList.RemoveItem(int index), raise a CancelableEvent.

Copyright (c) Marimer LLC