-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Promote the Anemic Domain Model as best practices? #7460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think ever demo apps should demonstrate best practise, and at the Symfony Demo application some entities has few "not DTO" behavior like Comment::isLegitComment(). May be makes sense to add more behaviors to the entities and remove some anemic domain model marks like "stuppid" setters unnecessary in domain model like setAuthor (in a reasonable domain model author property should set only once on entity creation). |
Thanks for proposing this improvement. To move the discussion from the abstract to our specific application, which methods do you propose to add to our four entities? There's no need to show the code of those new methods, just their names. Thanks! |
That's Data Mapper Pattern is for. A simple mapper interface. Adding more behavior than necessary deals with going to against the pattern. Doctrine isn't about Active Record. |
Even if this issue is older, I'm closing it in favor of the newer #8893 issue where some people are proposing to make this change not only for the Best Practices doc but for the entire docs. Thanks! |
(I just found this issue randomly.) I want to mention: The idea that "anemic domain model" === bad is not as clear as you may think. A lot of recent articles suggest that an Anemic model may very well be superior to a rich domain model. Of course it also depends on how you do it, not whether you call it rich or anemic. |
I was looking at the Symfony Demo application, and then I asked myself: it's really okay to promote anemic domain model as "best practice"?
I was reading the Doctrine Mapping Information section in particular:
But real entity has behaviors. From what I read there, I understand that "Doctrine entities are basically DTO".
I acknowledge that's the simpler way to explain how to build your "model", and for a demo app it's okay, but it isn't really a good practice, isn't it?
The text was updated successfully, but these errors were encountered: