From: Ralf E. S. <mo...@re...> - 2002-11-14 18:50:16
|
Hi, at the moment i spent some time on a small application using hibernate. I've did most of the domain's modeling and implementation. Now i have to decide where to place the database (say hibernate) dependent code. * Put everything into the domain classes. * Implement something like a "Home" interface * Implement some sort of component-like / "Service" interface Domain Classes with database access This implementation strategy seems to be the simplest one of all. Database access is at most implemented as static methods of the domain class. But unfortunately this establishes a very strong link between the domain classes and the persistence provider. If i decide to change the persistence provider for any reason, i have to modify all domain classes. Implementation of a Home-Interface This solution seems to keep things moderate simple. Each domain class (e.g. Actor) owns one associated "home interface" (e.g. ActorHome). Using some Factory it is possible to obtain a specific implementation (e.g. ActorHomeHibernateImpl) of that interface. All communication with the underlying persistence provider is channeled through this interface. The domain classes will be (almost) free of code dealing with the database (Lifecycle etc. seems to be still a problem). In this case i have to provide some abstraction for the persistence services (update(), delete(), TX-management). Implementation of Service like structures This is more or less the same idea like above but with coarser granularity. In this case i think about interfaces covering note single domain classes but semantic groups of them. In this way something that smells like a "component" (with its own lifecycle) could be implemented. Using this strategy the Service-Interface would behave also as a service provider for the domain classes. But this design could offer some chances to reimplement parts of the application using different persistence providers (requires the domain classes using the Service-Interface if crossing "component" borders). At this moment i'm not sure wich basic design i should use. Please drop me some notes about this topic. * Which is your preffered strategy? * Why have you choosen your way? * What are the benefits or the drawbacks? regards, Ralf E. Stranzenbach |