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?
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
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!
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" ). 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
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.
Copyright (c) Marimer LLC