Business logic’s paradox: the barber’s storyTags:
Inspired by Model practice’s last posts I will try to illustrate a business logic’s paradox on the barber’s paradox taken as a business rule ;)
The barber’s paradox: “The barber shaves only those men in town who do not shave themselves! Who shaves the barber?”.
The first sentence is the business rule: “the barber shaves only men who do not shave themselves”. The second sentence is not a business rule but a comment. A lot of misinterpretations when coding or modeling business rules come from comments turned into rules: “Hum… As I understand the rule there is a problem: who shaves the barber?”. From that point one can:
- Send the rule back to business guys any telling them the rule is not good (not the worst option ;))
- Imagine some ways to avoid the apparent paradox, among worst bypasses is designing an exception for the barber taken as a kind of man, and either proposing the solution to business guys (good option) or keeping it at technical level (business guys won’t understand and we need to code that rule…)
Both cases cost time, at least, or lead to inaccurate behaviours and maintenance costs, at worst. The rule in itself is clear and non ambiguous if seen in a real world context (which should always be the viewpoint to adopt when dealing about building applications intended to be used by real people with a real business!):
- There is a town, with men who need to be shaved. They can choose to shave themselves or go to the barber to get shaved.
- The barber offers a service: shaving. We can’t say for sure here that there is only one barber in town. And we don’t know the ratio men who shave themselves/number of men in town so we don’t know exactly if barber is a profitable activity or a business promise to growth. By the way, nobody tell us that “the barber” is a man and that he is alone: it can be a shop with employees, it can be a human being… A woman ;)
- Is there a problem if the barber is a single man who so need to be shaved? Not at all. The barber, as a man, is able to shave so he probably shaves himself. He may also ask for someone else to do it: nobody tell that only the barber has the right to shave. He may also go to the barber: himself as a barber will shave himself as a man.
- In fact, “barber” is an ability or a job, and may so be taken as a role not a person.
So. I tell there is no problem. However, how can I be sure that my (sensible) interpretation is the good one compared to what business guys had in mind when they wrote the rule? By asking them! And, as a communication support, a model would be a great help to describe this lack of complexity which is a kind of business logic complexity ;)
Featured image taken from http://bollywood-sapna.over-blog.com/article-23221027.html