One team, one language
Posted on June 23rd, 2010 by Sandro Mancuso
This post was originally published here by Valtech UK consultant Sandro Mancuso.
On a previous post I was discussing, among other things, how code often doesn’t represent the business properly. The code “satisfies” the business requirements but doesn’t express them very well. The main reason for that is because we, developers, like to abstract business terms and rules into technical implementations and patterns.
Very often, we discuss the user stories (requirement documents, use cases, whatever the methodology used is) with the “domain experts” and as soon as we understand what needs to be done, we map the requirements to a technical design (actions, services, entities, helpers, DAOs, etc) that is completely meaningless to the domain experts. Sometimes, even among developers themselves, different names and expressions are used to refer to the same thing. The main reason is that different developers talk to different domain experts and come up with different abstractions. As a result, the usage of different terms to describe requirements leads to confusion, duplication of code and unpredictable behaviour in the system.
The first step towards an expressive and domain-focused design is to have a common language among ALL members of the team. ALL means ALL: developers, domain experts (business analysts, users, product owner, etc), testers, project manager and anyone else involved in the project.
Developers very often say that domain experts don’t understand objects and database and because of that, they need to “translate” business requirements into software design. However, we developers don’t understand the business as well as the domain experts do, what more often than not, leads to imperfect and confusing abstractions.
The Ubiquitous Language
A language structured around the domain model and used by all team members to connect all the activities of the team with the software.
The Ubiquitous Language is one of the most important things, if not the most, in Domain-Driven Design. The main idea is that the whole team speaks a single language, that is the business language.
In order to capture the ubiquitous language, it is mandatory that you work on a iterative software development environment. Trying to capture the ubiquitous language up-front could straitjacket the whole process, inhibiting team members to make the necessary changes along the way. As the language is used to express the business requirements, it is natural that it evolves during the lifetime of the project, where new terms are added, deleted and also re-defined.
Methodologies like Extreme Programming (XP) says that the only documentation should be the code. Not even comments on the code are appreciated, since they can easily get out of sync with the code. The code should be the only documentation since it is the only one that represents exactly what the system does.
On the other hands, we have UML (Unified Modeling Language), that in theory, should be a great candidate to document the ubiquitous language since the whole purpose of UML was to document requirements and express them in a language that is common to developers and business people.
In summary, showing code during discussions with domain experts, testers and other members of the team during a design session is not exactly a fantastic idea. Also, using just UML, because of its bureaucracy, rules and details is also a bad idea. The whole UML notation could easily straitjacket the creative process during the exercise.
There are many discussions about what would be the best way to capture the ubiquitous language. My preferred way is to draw diagrams (boxes and arrows mixed with some well understood UMLish notation) where each box represent a “domain object” (aka domain concept). A domain object can be anything that is expressed by the business, like client, organisation, product, route specification, sales system, etc. They would all be boxes. Add to it a few arrows linking the boxes and with just a couple of words explaining how they related to each other. Sometimes a mixture of a class and sequence diagram (or an active diagram) can be very helpful, but don’t get to picky about any notation. Preferably, draw on a white board, take a picture and store that on the wiki. For further sessions, just open the wiki and re-draw just the bit of the design that is important to the feature being discussed. Make the necessary adjusts on the white board, take another picture and stored it on the wiki again. There is much more to that, if you want to dive into agile modeling, but I will leave it to another post.
This goes way beyond transforming nouns and verbs into classes and methods. Taking the examples above, for example, client, organisation and products could be transformed in entities; route specification could be a strategy class used by a routing service (that would also need to be added to the diagram and to the ubiquitous language); sales system would be an external system that we need to integrate to, etc.
Making the code more expressive
- Don’t try to model everything. Focus on the core of your application. We are not working on a waterfall or Unified Process project here.
- Try to model just the key concepts of the domain problem;
- Do not clutter your models with too much details. Keep it focused on the main responsibilities;
- Limit your discussions and changes in the model to the business concepts (domain objects) related to the user story being discussed;
- Don’t add architectural concepts like DAOs, Actions, etc. We are not writing implementation diagrams.
- As your application grows, break the application into multiple models (domains), explicitly defining the context and boundaries within which a model applies. This is called Bounded Context in Domain-Driven Design.
- Avoid thinking purely on the implementation when designing your model. Understanding and modeling the business is the most important thing here.