How to handle requirements that "mix" domain and interface?

4

Whenever I develop some software I try to leave the domain model without being influenced by issues relating to other layers of the application such as general technologies and interface issues.

In fact, the domain model contains a code template of the problem being solved, and the goal is to encapsulate the rules and business logic. All of the functionality itself should be within it.

It turns out that recently in a project I received an application of the following type:

  

In the contact status record you should be able to choose a color for that status. From there, when listing the contacts in a table, the line of a contact should be painted with the corresponding color of its status.

The application is very simple and implementation too. It's just that I was a bit worried because it seems to me that to implement this we ended up mixing the domain with interface issues.

Actually, the most practical way I would imagine doing this would be: given the class StatusContato a Cor property of type string is stored which stores a hexadecimal code of the color. From there the interface manages how this color is saved and used.

Although it works, this is worrying. If we only think about the domain, only in the business, Cor is not a characteristic and not something associated with StatusContato . It is merely something of the user interface.

I can imagine several other requirements of this type, where the user when submitting the requirement mixes domain issues with interface issues.

In this sense, how can this impasse be resolved? How can this kind of requirement be addressed without endangering the domain model with interface issues?

    
asked by anonymous 08.07.2016 / 04:35

1 answer

4

I believe it's not exactly a problem of going over layers. You are very focused on the domain as an abstract thing and forgetting that the business layer has to model the customer problem, not a generic problem.

For your client, StatusDoContato has a color . It may be that StatusDoContato of a competing company does not have, but that of your client has.

That is not to say, of course, that there is no room for separation of responsibilities. It is the role of the Presentation layer to decide where it will show this color (and how it goes and if goes), but it is the role of the other layers to store and manage the color saved. If a requirement comes in the future that says, for example, that the user can select a color from several predefined and labeled (red, blue, purple), it will have a part of it in the Presentation (a selection list) and a part in the business layer (convert that selected value to a hexadecimal and have it saved).

Moral of the story: if you think the way you are thinking, even the status name can be seen as a part of the Presentation layer, since it has a visual representation (characters on the screen) and may be displayed. Your Model and your business layer have to model the data and the domain of your client and your client wants a software, in the end.

    
08.07.2016 / 06:46