Repository – domain driver design – repository and polymeric roots

I have a domain model that includes forums.

I have forums, posts, and post entities.

The forum is a Independent entity. That is, it does not contain threads as part of the aggregation. This is because threads are not owned by a specific forum (you can move threads to other forums).

I don’t know if I should build posts The model is part of the thread aggregation. There can be no posts without threads. To delete a post, you must delete the post and tell me to make the post part of the post aggregation.

The only thing is that you also edit the post Posts can be obtained separately. That is, when editing posts with its id.

So I think it is good to have a post library for this purpose, instead of having to get the thread, and then get the correct method through the thread entity The only way to have a separate post library is that when adding a post, i.e. addPost(Post), you need to make sure that the thread ID has been assigned to the post entity. Using aggregation I think you will There is an addPost method on the thread entity.

Should I consider the limited background? Can I have a post entity and repository, and a thread aggregation containing the post entity?

If I am not using thread/post aggregation, how do I deal with deleting a post when I delete a thread? Should I create a service that calls deleteThread(Thread) in the thread repository and deletePostsByThreadId(id) in the post post repository?

What DDD method is there?

I want to know if DDD is a good idea in your case. I mean forum Essentially data-oriented. Perhaps you should consider one of the easiest ways to query your data using only classic data-oriented techniques. (i.e. LINQ, Hibernate, pure SQL, Entity Framework or whatever you want, (Depending on your platform)

Your program may not require a domain layer, or you will end up with a ForumDTO class that holds data, and a forum that holds business logic, for posts or threads Saying the same thing seems to be an anti-pattern to me.

What do you think?

Update

I suggest you read Eric Evans’s book, it has good examples of complex fields, among which DDD is very suitable.
After reading the book After that, I enthusiastically applied what I learned, but I have seen some case data-oriented methods are more suitable.

For me, the forum has almost no complex domain logic, so You will eventually establish a 1<->1 mapping between the data layer and the domain layer, which means duplication and overhead like I said.

See the description of your domain, your method It seems to be data-oriented.
For example, intuitively forum HAS thread and thread HAS post, the domain you describe is not reflected, and you seem to normalize your object model to fit your database schema (will be normalized).< /p>

The forum seems to be the best class to become the aggregate root (it is more intuitive)

If you really want to use the DDD method, you can inject the repository in the entity and follow your requirements Use the meaningful name of the domain object as thread.GetLastPostOf(User User).

But when you say that you should have a repository with a GetPostById method, I agree with you.

I have a domain model that contains forums.

I have forums, posts, and post entities.

The forum is a Independent entity. That is, it does not contain threads as part of the aggregation. This is because threads are not owned by a specific forum (you can move threads to other forums).

I don’t know if I should build posts The model is part of the thread aggregation. There can be no posts without threads. To delete a post, you must delete the post and tell me to make the post part of the post aggregation.

The only thing is that you also edit the post Posts can be obtained separately. That is, when editing posts with its id.

So I think it is good to have a post library for this purpose, instead of having to get the thread, and then get the correct method through the thread entity The only way to have a separate post library is that when adding a post, i.e. addPost(Post), you need to make sure that the thread ID has been assigned to the post entity. Using aggregation I think you will There is an addPost method on the thread entity.

Should I consider the limited background? Can I have a post entity and repository, and a thread aggregation containing the post entity?

If I am not using thread/post aggregation, how do I deal with deleting a post when I delete a thread? Should I create a service that calls deleteThread(Thread) in the thread repository and deletePostsByThreadId(id) in the post post repository?

What DDD method is there?

I want to know if DDD is a good idea in your case. I mean the forum is essentially data-oriented. Maybe you should consider one The easiest way to query your data using only classic data-oriented techniques. (i.e. LINQ, Hibernate, pure SQL, Entity Framework or whatever you want, depending on your platform)

Your program may not need a domain layer, or you will end up with a ForumDTO class that holds data, and a forum that holds business logic, the same thing for posts or threads, it seems to me Anti-pattern.

What do you think?

Update

I suggest you read Eric Evans’ book, it has very good examples of complex fields, among which DDD is very suitable.
After reading this book After that, I enthusiastically applied what I learned, but I have seen some case data-oriented methods are more appropriate.

For me, the forum has almost no complex domain logic, so You will eventually establish a 1<->1 mapping between the data layer and the domain layer, which means duplication and overhead like I said.

See the description of your domain, your approach It seems to be data-oriented.
For example, intuitively forum HAS thread and thread HAS post, the domain you describe is not reflected, and you seem to normalize your object model to fit your database schema (will be normalized).< /p>

The forum seems to be the best class to become the aggregate root (it is more intuitive)

If you really want to use the DDD method, you can inject the repository in the entity and follow your requirements Use the meaningful name of the domain object as thread.GetLastPostOf(User User).

But when you say that you should have a repository with a GetPostById method, I agree with you.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2356 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.