--
The only way to go fast is to go well.
---
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discu...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.
I find ORMs are just fine for clean architecture, but they need to be a detail. They've got to be hidden behind your persistence layer interface or you're going to hurt eventually. But as a way to implement that interface, they may be great.That means: it's fine if the entities have to extend some ORM class, but you'll have two trees of entities. Or, if your ORM is sufficiently magical, you may be able to use your business entities and map them in, though I wouldn't recommend it because you often want the persistence implementation and the business entities to vary independently. Your persistence implementation will change due to changes in your business objects, but the reverse should never be true. If your persistence implementation returns magical proxies, those proxies should be there to enable some well-specified feature of your persistence layer, so any behavior you're worried about ought to be covered by integration tests on the persistence implementation.Lazy-loading should be an optimization to help you have to manage the object graph less explicitly for use cases, but it can be a sign you haven't thought carefully about the data needs of some particular use case when invoking it. It generally adds round-trips to the database, which can harm performance, and opens you to invisible n+1 query problems or memory exhaustion on big relations, so you're trading those concerns for simpler management of what data to load before starting work.When I look at designing integrations with ORM, I often think, "what would have to change if I decided to use raw SQL, noSQL, or REST persistence instead?" The ideal answer is, "only the implementations of the interface of my persistence layer, and nothing in any other module except maybe main, and I'd know it would work when I was finished because all the integration tests passed."
On Sun, Jun 16, 2013 at 10:26 AM, Daniel Karp <danie...@gmail.com> wrote:--
This is related to my other thread about persistence as a detail and testing, and is particularly aimed at any fellow readers/watchers who use PHP.I started writing a small application deferring decisions about persistence for a while--when it came time to implement the database I found that it was very tempting to implement the persistence using an ORM (object-relational mapper), because I thought it would allow me to store my entities with not much change in the way they were implemented.The issue is this: most ORMs, in PHP anyway, require your entities to extend some base class of the ORM. Of course, that is a definite no-no for clean architecture--the Entities should know nothing about the persistence layer. Theoretically, I could put those ORM-aware "entities" entirely in the Database implementation, and translate them into my application entities in that layer, but having two sets of entities seems kind of silly.
Doctrine ORM is a bit different; it does NOT require your entities to derive from a common parent at all, so I thought, "great, I can use these in a clean way". I implemented the application with Doctrine, but now I think I was a bit fooled by not understanding the details of Doctrine: although the entities do not extend from a common parent, the objects returned by the entity manager, when the objects are retrieved from the database, are NOT purely instances of your entity objects; rather, they are instances of Proxy classes, created by doctrine, that supposedly behave just like your entities, but override some of the getters to allow for lazy-loading of relationships.To me, this seems almost as bad as, if not worse than, having the entities derive from some class in the ORM. If the entity manager returns objects that are not really instances of my classes, how can I trust the tests that DON'T use doctrine for the persistence?Is using an ORM just incompatible with clean architecture? Am I worrying too much about the use of proxy classes by Doctrine?
John Stoneham
ly...@lyrically.net
either way, it's plain simple: the business logic entities and interactors are the most abstract part of your system. they don't have dependencies to components with a lower level of abstraction (e.g. ORMs that only Plug in to your system)
--
You received this message because you are subscribed to a topic in the Google Groups "Clean Code Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clean-code-discussion/EyTIuGt_yTA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clean-code-discu...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discussion+unsub...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.
--
The only way to go fast is to go well.
---
You received this message because you are subscribed to a topic in the Google Groups "Clean Code Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clean-code-discussion/EyTIuGt_yTA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clean-code-discussion+unsub...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.
--
The only way to go fast is to go well.
---
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discussion+unsub...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.
--
The only way to go fast is to go well.
---
You received this message because you are subscribed to a topic in the Google Groups "Clean Code Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clean-code-discussion/EyTIuGt_yTA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clean-code-discussion+unsub...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.
--
The only way to go fast is to go well.
---
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discussion+unsub...@googlegroups.com.