I'm trying to come up with a reusable warning piece for the business objects in a project I'm working on. Before saving one of our business objects, sometimes we need to warn the user of what the potential impacts are. Say my business object was named "Company". Company.Delete() will get rid of the company and not really care about what happens. That particular Company may have 10,000 employees that would be pretty disappointed if it was that easy to put them out of work by accident...
So the UI requires a way to see something like:
- Deleting "Company A" will put 10,000 workers on the streets.
- Deleting "Company A" will leave 1,000,000 shareholders with useless stocks.
So I could just make a function like Company.GetWarnings() that returns some strings to display, but I want something a bit better than that. If Company.GetWarnings() returned the first warning above, I would want the UI to be able to know what that warning means. For example, if the first warning were to appear, the UI would know what it means and handle the situation by providing a link like:
- Deleting "Company A" will put 10,000 workers on the streets.
- Would you like to find new work for these employees? 'Click Here'
Or perhaps another business object would use Company.GetWarnings() and knowing that some workers would be put out of work, it could automatically send out severance packages. You get the idea...
So I guess the requirement sounds pretty easy, but I'm getting kind of lost in the minor details. Mainly, what kind of structure could I give GetWarnings() so that it returns:
- The warning message.
- Some way to identify what kind of message it is.
Leaving me to my question:
Does anyone have any best practices, examples, or suggestions to implement this kind of warning system? My main concern is with #2. There will be a ton of different kinds of warning messages, so I don't want to just return say...a Dictionary where the int is an Id of the type of warning. That would get hard to manage fast.
Thanks for any advice you can give.