Passing "Are you sure" message across layer boundaries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like a particular business object to ask for validation when a
property is set to a specific value. In this case, I have a TimeStart
property and a TimeEnd property. When creating a new object, the default for
these properties is Now. However, saving the data with both values set to now
would be highly unusual, so I'd want the class to ask for verification. I
think this rule should be maintained by the class and not the UI (a windows
form).

One thought I had is to expose a boolean property called ZeroTimeAllowed.
The default would be False. If the rule found that ZeroTimeAllowed is false
and the time properties are the same, I would throw an exception. The UI
could then show a messagebox and then change the ZeroTimeAllowed to True if
the response is Yes.

I'm not crazy about this idea, because there would be nothing stopping the
UI developer (in this case, myself) from always setting ZeroTimeAllowed to
True.

Any advice would be helpful.

Thanks,
Barry
 
I would do it the way you're not crazy about. Doing MessageBoxes in the
business layer is just icky. (Yes, that's a technical term.)

One would hope the UI developer (in this case, yourself) would not set
ZeroTimeAllowed to true all the time, but if you needed to, it would give
you that flexibility.

Robin S.
 
You can throw in another hacky fix to get it to work.

a


private int m_verifyWasRunCounter = 0 ; // int


Use this so they don't just set ZeroTimeAllowed to true, and move on.


if m_verifyWasRunCounter is 0, then you know they just set it to true.
if you increment it, then at least you know they tried once, and then
manually set it.

??
I think that might work.
 
Thanks for your replies.

I'm using Rocky Lhotka's CSLA framework. It maintains a list of broken rules
and warnings in the BO's base class. In my UI, I can check whether there are
any warnings and display a msgbox with the warning descriptions. The business
object maintains the warnings, but the UI does the alert logic.

Barry
 
Back
Top