Note that there are some explanatory texts on larger screens.

plurals
  1. PODDD - Entity creation and validation responsibility
    primarykey
    data
    text
    <p>I'm interested in DDD (Domain Driven Design) in the last days, but I can't figure out the responsibilities of who creates and validates the entities. Ill break this questions to cover different scenarios.</p> <ol> <li><p>Regular entity (Possibly with value object). As an example lets take a user who is identified by Email. I have a UserFactory that receives an array of data (possibly from form POST), and return me a new UserEntity. Should the factory validate the integrity of the data (ex: string given as Email is a real email, passwords in password field 1 and field2 match and etc)? Should the factory validate that no such user exists already (we dont want to register two users with the same email)? If yes should it do it my itself or using the UserRepository?</p></li> <li><p>Aggregate entity. Lets assume we have a Post entity and Comments entities. I want to get post 12 with all its comments, so I do something like</p> <p>$post = $postRepository->getById(12);</p></li> </ol> <p>How getById should be implemented? like this:</p> <pre><code>public function getById($id) { $postData = $this-&gt;magicFetchFromDB($id); $comments = (new CommentRepository())-&gt;getForPost(12); return new PostEntity($postData, $comments); } </code></pre> <p>Or maybe the post responsible for lazy creating its comments, something like:</p> <pre><code>class PostEntity { public function getComments() { if(is_null($this-&gt;_comments)) $this-&gt;_comments = (new CommentRepository())-&gt;getForPost($this-&gt;_id); return $this-&gt;_comments; } } </code></pre> <p>? I'm very lost here and there is not enough information with examples for DDD in PHP, so any help will be appreciated!</p> <p>Thank you a lot, skwee.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload