Where to start when creating a domain model?

Let's say I made a list of concepts that I will use to create my domain model. In addition, I have a couple of use cases from which I made a couple of sequence diagrams.

When creating a domain model, I never know where to start:

  • Designing a model, in my opinion, will be a system. This, if I am modeling a human body, I start by adding the concept classes Heart, Brain, Core, Stomach, Eyes, Head, etc.
  • Start by developing what you need to do to use. This, if I have an example of use, which is to force the human body to absorb something, I will first draw class concepts for the Mouth, Throat, Stomatin, Subsoil, etc.

The order in which I do things doesn't matter? I would say it would probably be better to try to design from Use Case concepts, since they usually you want to work with, and not other concepts that, although they help to describe the whole system well, most of the time may not even be needed for the current project . Is there any other approach that I am not considering here? How do you usually approach this?

thanks

+4
source share
6 answers

I would start by drawing a class diagram with all the relationships and implement only those classes that are necessary in accordance with the requirements of your application.

You can use an anemic approach (attributes plus getters and setters) so that everything is in order and avoid the steps of writing business logic at the same step. With an anemic model, logic goes into the appropriate service class. So you can consider using cases later.

I know that some people don’t appreciate this way of doing something, but it helps in maintenance and avoids some addiction problems.

Answer the elysium devoured question below :

In terms of analysis, starting with use cases (What) and then moving on to a class diagram (How) sounds like a good rule of thumb. Personally, I would make a Sequence Diagram (When and Who?) After that, since you would need to know what process / object messages to send.

Besides the fact that I believe that UML is just a way of modeling the system / project, and not the methodology itself (unlike Merise, RAD, RUP, Scrum, etc.). Nothing prevents someone from starting with any chart if they have enough information to complete it. In fact, they must be executed simultaneously, since each of the diagrams is a different perspective of the same system / project.

So it all depends on how you analyze. During my studies, I was taught the approach with a hard waterfall, where you do a complete analysis from start to finish, before creating the code. However, in practice, everything can be different, since the imperative may be to create a working application in minimal time.

For example, I recently got acquainted with the Scrum methodology for exercises related to creating a website where people can publish their fiction. Since there was a time limit and a clear idea of ​​what should be achieved, we immediately started with a bare-bone class diagram to represent the domain model. The use cases were then inferred from the series of layouts we released.

From memory classes were "History", "Chapter", "User" and "Category". This last class has been canceled in favor of the more flexible Tag class. As you could imagine, a complete class diagram of an existing project will be much more complicated due to the use of domain-based architecture and the features of the Java programming language.

This approach can be considered sloppy. However, a website like this can be easily done in a couple of weeks using an iterative process and still well-designed. The advantage that the iterative process has in relation to the approach to the waterfall is that you can constantly adjust the requirements as you move. A frequent change in requirements is a reality, as people often change their minds and the ability to create a working application after each iteration, allowing them to stay on course for so long.

Of course, when you present a project to a client, a full analysis with UML diagrams and some layout screens will be preferable so that they have an idea of ​​what you are offering. This is where UML appears. After you have explained some visual conventions, a person should be able to understand diagrams.

To finish, if you are in a situation where you are trying to determine what the client wants, it is probably a good idea to gradually create a questionnaire that you can bring with you. Interviewing a person is the only way to determine which concepts / functions are really necessary for the application, and you should expect to return to clarify some aspects. Another tip is to do some quick research on the Internet when you come across a subject you are not familiar with.

In your example, this will go through the basics of anatomy. Among other things, this will help you decide what the model should contain and what grain it should have (which group of organs should be taken into account? How accurate should it be? Only models should be modeled or they should be decomposed into their components, such as tissues, cells, chemical composition, etc.?).

+2
source

Regardless of whether DDD or not, I would recommend identifying the ubiquitous language (UL) by interviewing the owner (s) of the product. Establishing communication so that you and the product owners speak the same language, not only with communication assistants, but also the opportunity to discuss the project in general terms, as a rule, helps to determine the domain model.

So my answer is basically to discuss, listen and learn. The software serves. Understanding the model from the point of view of experts will lay a solid foundation for application.

+4
source

I think a place to start would be something that feels logical and comfortable. It is probably best to start with use cases, as they give you clear direction and goals and help you avoid YAGNI situations. Given that you should try to develop a strong domain model, this is not a big deal, as the whole picture of the domain is important.

+2
source

I would like to share my experience in such situations. I usually start by writing tests and code. And try to cover one end to the end. This gives me a fairly complete picture of the problem, and in the end I also have something working with me that I can show to my client. In most cases, subsequent stories are built on top of the previous one, but it also happens to me that subsequent stories require changes in the previous model that I came across. But this does not affect me, since I already have good coverage for testing. Thus, I came up with a model that is suitable for the current problem, and not a model that displays the real world.

0
source

You start with business requirements that can be formalized or not. If formalized, you will use usage diagrams.

For example, examples of usage diagrams for an e-commerce application: http://askuml.com/blog/e-commerce/

http://askuml.com/files/2010/07/e-commerce-use-case.jpg http://askuml.com/files/2010/07/e-commerce-use-case2b.jpg

Of these use cases, you can naturally infer business units: product, product category, shopping cart ... that begin to prepare class diagrams.

This is best practice in many methodologies, but it is also just common sense and naturalness.

0
source

Short answer

Choose a usage example, draw a collaboration diagram (and class diagram) to implement domain objects. Focus only on those objects that were involved in achieving the goal of use. Write a TDD test case to set expectations and gradually model domain classes to meet expectations. TDD is very useful for understanding expected behavior, and it helps to get a cleaner domain model. You will see that your domain is gradually developing along with TDD expectations.

Long answer

My personal experience with DDD was not easy. This happened because we did not have the necessary grounds. Our team had many weaknesses in different areas; the requirements were not fixed properly, and we had only a representative of the client who was not really useful (did not participate). We did not have a proper release plan, and the developers lacked object-oriented concepts, best principles, etc. The main problem we are facing is to spend so much time understanding the domain logic. We sketched class diagrams and we never got the domain model correctly, so we stopped doing this and found out what went wrong. The problem was that we tried too hard to understand the logic of the domain, and instead of reporting, we made the conditions for requirements. We decided to change our approach, we applied TDD, we started writing the expected behavior and coded the domain model to meet the expectations of TDD. Sometimes we get stuck in writing TDD tests because we did not understand the domain. We immediately spoke with a customer representative and tried to get more information. We have changed our release strategy; apply a flexible methodology and release often so that we get real feedback from the end user. However, to ensure the expected end-user expectation at the right level. We reorganized based on feedback, and thus the domain model evolved gradually. Subsequently, we applied design patterns to improve reuse and maintainability. My point is that only DDD cannot survive, we must create an ecosystem spanning the domain, developers must have strong OOP concepts and value TDD and unit test. I would say that DDD is on top of all OOP methods and methods.

0
source

Source: https://habr.com/ru/post/1312393/


All Articles