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?)
例如,我有一个客户端移动应用程序和一个服务器。服务器包含一些验证和业务逻辑。移动应用程序知道服务器的API。例如,移动应用程序应该在/POST/{postID}上调用POST HTTP方法,并传递一些参数来编辑一些POST。Post.dit()方法应该是什么样子的?(接口应该在哪里调用?)
Should I pass some PostService to Post entity to call API? Then is PostService a domain service?
我是否应该将一些POST服务传递给Post实体以调用API?那么售后服务是域服务吗?
更多回答
优秀答案推荐
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.
不是的。你不应该把邮政服务交给PostEntity。实体必须具有更改其自身实例状态的方法。PostService会影响任何PostEntity实例。
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.
您可能更愿意创建一个ApplicationService来集中此逻辑。ApplicationServices也称为用例或命令/查询处理程序。基本上,序列诊断的一个实现然后,您的客户端(移动应用程序)将调用这些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.
DomainService和ApplicationService都是DDD的概念,但它们在语义上是不同的,如果你不知道其中的区别,我建议你看看这篇文章。
更多回答
So, If all business logic is placed on a server, then a client app should not have domain services only application services?
那么,如果所有业务逻辑都放在服务器上,那么客户端应用程序不应该只有域服务,而应该只有应用程序服务?
Even the application services are placed in the server. Your client app shouldn't have any business logic. The client app should have just the logic for the experience of the user, and call the application services.
甚至应用程序服务也被放置在服务器中。您的客户端应用程序不应包含任何业务逻辑。客户端应用程序应该只具有用户体验的逻辑,并调用应用程序服务。
我是一名优秀的程序员,十分优秀!