We'll discuss Application Services in the following chapters, but for now, let's check different approaches for making a Wish. The first approach, particularly for a novice, would likely be something similar to this:
class MakeWishService{ private $wishRepository; public function __construct(WishRepository $wishRepository) { $this->wishRepository = $wishRepository; } public function execute(MakeWishRequest $request) { $userId = $request->userId(); $address = $request->address(); $content = $request->content(); $wish = new Wish( $this->wishRepository->nextIdentity(), new UserId($userId), $address, $content ); $this->wishRepository->add($wish); }}
This code probably allows for the best performance possible. You ...