As mentioned in CQRS principles, a
Command is a representation of a single domain use case. To prevent
Command Handlers from duplicating code and depending on each other, it is usually best to avoid implementing the actual logic in the
Command Handler itself, and delegate it to
Domain Services instead. These services are responsible for logic such as:
Here are some principles for implementing a Domain Service:
ObjectModel for writes, as long as such class exists.
ObjectModel exists, then this query MUST be delegated to the appropriate repository class which must ensure that no legacy exceptions are thrown. If the related
ObjectModel already implements such method, then the repository must delegate its implementation to the
ObjectModel contains fields validation, it MUST be validated by a dedicated validator class before persisting to database (e.g. when using
save methods). It ensures that legacy PrestashopException is not bubbling up and each validation error can be identified by a dedicated exception or exception code.