tag:blogger.com,1999:blog-36547168.post7010897778886218762..comments2023-11-25T11:00:42.257+01:00Comments on Invisible to the eye: Object-oriented mythsGiorgiohttp://www.blogger.com/profile/03558287012747987157noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-36547168.post-32801196368624619972009-10-13T18:55:40.968+02:002009-10-13T18:55:40.968+02:00You're right, the different uses of "Enti...You're right, the different uses of "Entity" term overlap here. The distinction Entity/Service can also be called newable vs. injectable and that's what I mean. If a DDD-Entity has reference to other objects, it becomes an injectable and so a factory is the right choice. The direct creation is limited to objects without collaborators (so there's no injection to abstract away) and with little behavior (so there are no problems in testing them in isolation). Examples are String, DateTime, ArrayObject... and also User if it's not a rich entity. In DDD the problem is finding a balance between rich/coupled and cohesive/anemic, and I prefer to never inject a service in an entity but only to pass it as a parameter when needed.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-79023971117848866682009-10-13T17:09:09.589+02:002009-10-13T17:09:09.589+02:00Then I don't understand this sentence:
"I...Then I don't understand this sentence:<br />"If BusinessObject is an entity, you can create it directly"<br /><br />Staying with the DDD pattern Entity, then it not only maintains its state but also its invariants at creation time.<br />And it also could be the root of an Aggregate.<br />The creation could be very complex, so I would almost never <br />do it without a Factory (or another creational pattern) for that ones. <br /><br />Another reason is also the creation of complex entities as a Whole object (not allowing partially invalid objects).<br /><br />Most of my Entities aren't simply "newable".<br /><br />And another question is: "Who creates an Entity"?<br />Does it come out of nowhere, can I "new" it anywhere?<br /><br />Perhaps I'm only a bit confused by your use of the terms entity/service.<br />Extended use of Services, at least in DDD, should be avoided where possible, else it could lead to an anaemic domain model soon.<br /><br />Just a food for thought.<br /><br />BTW:<br />Thanks for great articles!<br />;-)Don Zampanohttps://www.blogger.com/profile/09407908409871009413noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-55490007243852992392009-10-13T16:52:13.499+02:002009-10-13T16:52:13.499+02:00zampano,
I use "entity" as a wider term ...zampano,<br />I use "entity" as a wider term for describing every object which purpose in the domain model is to maintain state. This includes DDD Entity and Value Objects, but also every "newable" object like Java String and Map.<br />For a detailed explanation see: http://giorgiosironi.blogspot.com/2009/07/when-to-inject-distinction-between.htmlGiorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-34637574108666578392009-10-13T16:19:49.071+02:002009-10-13T16:19:49.071+02:00Hi Giorgio,
when you talk of "entities"...Hi Giorgio,<br /><br />when you talk of "entities", is it the same "pattern" like that one in DDD?Don Zampanohttps://www.blogger.com/profile/09407908409871009413noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-56429383116664608652009-10-13T10:17:05.618+02:002009-10-13T10:17:05.618+02:00James,
I've add a paragraph explaining that th...James,<br />I've add a paragraph explaining that these names are mostly examples (like BookRepository is). Client is only the standard name for the class which utilizes a pattern, such as an Abstract Factory. I use real names to distinguish between them in a phrase.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-14433313879034596062009-10-13T00:07:46.865+02:002009-10-13T00:07:46.865+02:00Interesting article. I fear I may have missed some...Interesting article. I fear I may have missed some things because if your terminology. Word like business objects are a little confusing. I look forward to your next article.<br /><br />JamesJafarhttps://www.blogger.com/profile/05749916623871860085noreply@blogger.com