Домой United States USA — software The Dangers of If Statements in Domain Logic

The Dangers of If Statements in Domain Logic

412
0
ПОДЕЛИТЬСЯ

The if statement found in most programming languages has two major roles, validating input to protect the domain from erroneous data, and for dealing with business logic inside the domain. Unfortunately, we spend too little time managing the risks from a business or domain perspective,…
The if statement found in most programming languages has two major roles; validating input to protect the domain from erroneous data, and for dealing with business logic inside the domain. Unfortunately, we spend too little time managing the risks of using if statements in logic from a business or domain perspective, Udi Dahan claimed in his presentation at the recent DDD Europe Conference in Amsterdam.
When buying things online, we look at different items and read details about some of them. When we find something to buy and add that to the shopping cart we also move from the query side to the command side of the interaction. One of the important questions Dahan thinks we should ask for any kind of command, is what would cause the command to fail, and emphasizes that we must distinguish technical failures, like a crashed web server or some deserialization error, which should be handled by infrastructure, from logical failures, like adding an item to a shopping basket just after the same item has been deleted from the product catalogue.
Checking if something is deleted is an example that often comes up in Dahan’s work with customers. For him, one step in dealing with problems like deleted items is to make a distinction between private and public data, and compares with a content management system where you edit pages and content, and finally make the information public by pressing a Publish button.

Continue reading...