Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I vote for the service layer. I've often struggled with trying to add as much logic on the Entity itself, and simply frustrated myself. Without access to the EntityManager, you're simply not able to perform query logic, and you'll find yourself using a lot of O(n) operations or lazy-loading entire relationship sets when you only need a few records (which is super lame when compared to all the advantages DQL offers).</p> <p>If you need some assistance getting over the idea that the Anemic Domain Model is always an anti-pattern, see <a href="http://www.slideshare.net/weierophinney/architecting-your-models" rel="nofollow noreferrer">this presentation</a> by Matthew Weier O'Phinney or <a href="https://stackoverflow.com/questions/258534/anemic-domain-model-pros-cons">this question</a>.</p> <p>And while I could be misinterpreting the terminology, I'm not completely convinced that Entities have to be the only objects allowed in your Domain Model. I would easily consider that the sum of Entity objects and their Services constitutes the Model. I think the anti-pattern arises when you end up writing a service layer that pays little to no attention to separation of concerns. </p> <p>I've often flirted with the idea of having all my entity objects proxy some methods to the service layer:</p> <pre><code>public function addVote($vote) { $this-&gt;_service-&gt;addVoteToThing($vote, $thing); } </code></pre> <p>However, since Doctrine does not have any kind callback event system on object hydration, I haven't found an elegant way to inject the service object.</p>
 

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