Em Tue, 15 Dec 2009 00:34:25 -0200, Geoff Callender <geoff.callender.jumpst...@gmail.com> escreveu:

However, if you're happy to stick with relational, then JPA can be your DAO. You choose your relational persister at runtime, eg. Hibernate, TopLink, OpenJPA, etc.

You can be happy with relational persistence now, but maybe not tomorrow. ;) Just to be very clear: when I say "JPA is not my DAO", I say "any class outside my persistence layer doesn't use JPA directly". As long as you define DAO interfaces that are technology-agnostic and your business rules classes use them, I'm happy with any DAO implementation. :)

I'm building a system right now with almost all business logic encapsulated in the entities. Most of the entity methods represent state changes (eg. toAccepted(..), toRejected(..), toBilling(..), toBilled(..)) and many of those methods either create related entities or call state change methods on related entities. This kind of encapsulation is exactly what OO was all about before EJB 1 and 2 came along and stuffed us back into a procedural world with an anaemic domain model ( http://martinfowler.com/bliki/AnemicDomainModel.html ). The total effect is like a myriad of state machines interacting with each other, just like the real world, and so far I'm really liking it.

I don't like anemic models, but I don't like entity classes that talk to DAOs or business rules classes, like the domain-driven model people love to do. I never have an entity class with a save() or findById() method. I like to think that an object must implement anything it can do inside its data structure, but never access anything beyond it (data store, external systems).

If your entities represent the real world entities and the developer can clearly see they implement the same behaviours as the real world entities then it seems to me that it is the "right" coupling!

I think we agree, but we didn't realize it yet. :)

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, software architect and developer, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to