Timeline for Representing business rules with exceptions
Current License: CC BY-SA 2.5
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 29, 2010 at 18:23 | comment | added | Adam Crossland | @Fede: it is the Business Layer's job to assure that every input is OK. If the UI is doing it then it is implementing business logic. Now, if it is the case that an input field is restricted to digits and the BL sees alpha characters, by all means throw an exception. Whenever a component recieves invalid inputs from another component, throwing an exception is logical and right. The interface has been broken, and the system is broken. However, validating inputs is very different than executing business logic. Two very different things. | |
| Oct 29, 2010 at 17:44 | comment | added | Fede | @Adam - Don't follow you with the separation of concerns issues. I don't expect anyone in the UI to handle a CustomerNameInLowercaseException (please, I also hope that exception doesn't even exist!). You can just handle a generic ValidationException. Besides, I'm 100% with you that the UI should only gather information, and all that thig. What I said before is that no matter what you do in the UI, the BL shouldn't assume that every input is ok. It's just some defensive programing. | |
| Oct 29, 2010 at 16:11 | comment | added | Walter | @Adam - Well said and exactly on point. | |
| Oct 29, 2010 at 15:24 | comment | added | Adam Crossland | @Fede: it's a question of separation of concerns. The UI is responsible for gathering the user's intentions and reporting feedback from the business layer. The business layer's job is analyzing the information gathered by the UI, analyzing it and either reporting back to the UI and/or asking the data layer to persist some data. There should only be loose coupling between these layers. Exceptions are a poor, poor approach to loose-coupling. Not only does it mean sharing actual classes between the layers but it also invokes a mechanism that is meant to handle unexpected failures. | |
| Oct 29, 2010 at 15:15 | comment | added | Fede | What I understand of what you said, is that you don't agree with the UI. I'm ok with that. I agree with you that a much more friendly UI wouldn't let you try to update something you're not allowed. But that doesn't mean that the validation and exception check in the business core is unnecessary. By the contrary, I believe they are a must. You need them to ensure that a badly programmed UI doesn't allow a BL misuse. | |
| Oct 29, 2010 at 15:03 | history | answered | Walter | CC BY-SA 2.5 |