DDD: Where to create entity objects?

I have three objects that must interact: User, SupportTicketand PhoneConversation. When someone calls for help, the User must have a SupportTicket assigned to him and PhoneConversation assigned to Ticked describing the call.

My question is: In which entity should I put the method CreatePhoneSupportTicket()that creates the new SupportTicket and PhoneConversation, connect them to each other, and finally connect the SupportTicket to the user?

I assume this cannot be on the user, because it violates SRP (the user does a few more things). But the method itself does more than one, it should create both SupportTicket and PhoneConversation. Is this a situation where a service is the best solution and then sets methods for entities? Thank you for your help!

+3
source share
5 answers

, . SupportTicket, new SupportTicket(currentUser) . , , CreateSupportTicket() new SupportTicket() . SupportTicket, , new PhoneConversation(). - factory, . , .

+2

... ... ? , "" , , . ? , . . Entity, . , . , , . .

( ) # 19

+1

Factory , .

+1

, .

, , ( , , ) - , . , , , , ID . , . , . .

, , , factory?

, ? , . , -

Ticket t = user.GetOpenTicket();
t.AddCall(currentCall);

. , , Ticket.AddCall user.GetOpenTicket .

0

It's hard to say without deep knowledge of your domain, but it would be wise to have aSupportTicketRepository.CreatePhoneSupportTicket(aUser, aPhoneConversation)

-1
source

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


All Articles