One Class Per Application Service

This is our preferred approach, and probably the one that fits all scenarios:

class SignUpUserService 
{
// ...
public function execute(SignUpUserRequest $request)
{
// ...
}
}

Using a dedicated class per Application Service makes the code more robust against external changes (Single Responsibility Principle). There are fewer reasons to change the class, as the Service does one and only one thing. The Application Service will be easier to test, seeing as it does less things. It's easier to implement a common Application Service contract, making class decoration easier (check out Sub section Transactions of Chapter 10,  Repositories ). This will also result in higher cohesion, as all dependencies are exclusively dedicated to a single use case.

The execution method could have a more expressive name, like signUp. However, the execute Command pattern format standardizes a common contract across Application Services, thereby enabling easy decoration, which comes in handy for transactions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset