clientdomain-driven-designentitybusiness-logic

How should method of DDD Entity look like in a client app?


How should I write methods in my entity in client app?

For example, I have got a client mobile app and a server. The server contains some validation and business logic. The mobile app knows the server's API. For example, the mobile app should call POST HTTP method on /post/{postID} and pass some params to edit some post. How should Post.edit() method look like? (Where should I call API?)

Should I pass some PostService to Post entity to call API? Then is PostService a domain service?


Solution

  • Should I pass some PostService to Post entity to call API? Then is PostService a domain service?

    Nope. You shouldn't pass the PostService to PostEntity. Entities must have methods that changes the state of itself instance. PostService affect any PostEntity instance.

    You probally will prefer to create an ApplicationService to concentrate this logic. ApplicationServices are also known as UseCases or Command/Query Handlers. Basically, an implementation of the Sequence Diagrama's UML Then, you client (Mobile App) will call these ApplicationServices.

    DomainService and ApplicationService are both concepts of DDD, but they are semantically different, I suggest you see this post if you don't know the difference.