In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to aggregate and divide in java, I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
With regard to the concept of aggregation, the discrimination of non-root entities in aggregation is based on the fact that they cannot exist without the root of the aggregation, for example, the order details cannot exist without the order, so the order details only belong to a non-root entity in the order aggregation.
But I have always thought that it is too abstract, and there should be a more rigorous and perfect way of judgment. So, in this article, let's consider a case:
Case background
On an information platform, users can log in and publish and read articles. So, at the beginning, the relationship between the two goes like this:
After that, there is a new requirement that users can comment on the article, so how to set up the comment entity? Let's think about it:
Comments must belong to an article, at least in terms of current needs, so comments cannot be separated from articles.
Comments must also be initiated by a user, and comments can not be separated from users.
It looks a little tricky. But in short, comments certainly can not exist independently.
If you follow what I mentioned in the previous article, you will probably fall into the above thinking, and you will probably think that the comment should be "the comment of the article", so the comment should belong to the aggregation of the article.
Design and analysis
But I feel awkward no matter how I look at it. Very awkward! But according to the previous rules, this should be the case. What is the problem?
Let's think about this: how are comments created? The product flow is as follows:
Users enter comments in the comment box at the bottom of the article and click submit
So the smooth conclusion of the code should be like this:
Comment comment = commentFactory.create (newCommentRequest)
But if you want to force the design of the article aggregation, it will be very uncomfortable:
/ / since the aggregate root is an article, be sure to find the article first, and then add a comment to the article Blog blog = blogRepository.getById (newCommentRequest.getBlogId ()); blog.addComment (newCommentRequest)
Of course, the word "awkward" is not rigorous enough, so use a more rigorous term:
Although the comment is related to the article, its creation process does not take place in the various lifecycle operations of the article, but is created independently, so it should be a new independent aggregation.
Specifically: the article has the process of creating, editing, reviewing, deleting and so on, but in this process, there are no comments, which means that comments are not a direct derivative of the life cycle of the article, although it is associated with the article and users, it is created independently and has its own independent life cycle (which can be modified and deleted separately).
So, the diagram should be
In contrast, let's look at the more common non-root entities, such as the user login log and the order change log, which are created in the process of user login and order operations. the life cycle is strongly bound to the root entity at the beginning.
So, this time, I summed up the following principles to determine whether an entity should exist as the root of a new domain aggregation, with priority from high to low:
Whether the creation process of the entity is completely independent, rather than relying on the command operation with some other entity
Whether the entity can be deleted / operated separately, rather than, for example, changing with the command operation of some other entity
Whether the entity has a separate list view, rather than having to rely on the view of another entity as a prerequisite (for example, the order log must find the order first)
Among them, (2) (3) is only used as an auxiliary reference, the most important thing is (1), if (1) can be complied with, nine times out of ten can be defined as an independent aggregation.
After reading the above, have you mastered the method of aggregation and partition in java? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.