barryhawkins
Jan 7th, 2005, 10:39 AM
My project team at work has a J2EE application that is a fairly typical Struts/Spring/Hibernate effort. One of our key goals is to maintain a well-layered structure that is intuitive and promotes good practice. The approach to Java packaging is a key factor in keeping a clean setup, but I haven't seen that much discussion about it. So, I figured I would throw ours out there and ask for input/feedback/submission of other samples.
Our application uses a persistence layer, a domain layer, a service layer, and a presentation layer. We are currently working out the service layer/domain layer boundaries through refactoring of some rather large service objects. The packaging scheme is below; I am using a ficticious prefix to avoid any privacy issues:
Java Packaging Scheme
com.acme.application
com.acme.application.action
com.acme.application.dao
com.acme.application.dao.hibernate
com.acme.application.domain
com.acme.application.domain.logic
com.acme.application.forms
com.acme.application.resources
com.acme.application.service
com.acme.application.service.spring
Persistence Layer
dao contains interfaces for DAOs to be implemented, and dao.hibernate contains the Hibernate implementations of the interfaces.
Domain Layer
domain contains the domain objects, also referred to as business objects; just how much business logic is contained in these is an ongoing discussion. Beyond the getters and setters for the required properties, validation may be included in them. domain.logic contains interfaces and implementations of more-complex objects that manage collections and/or hierarchies of domain objects. This is somewhat similar to the structure of the jpetstore sample application, from which we took the idea for this structure.
Service Layer
service contains interfaces for service objects that group and/or manage domain.logic objects within transactional boundaries. service.spring contains the Spring implementations of those objects. This allows for other implementations, such as Pico, if need be (although highly unlikely).
Presentation Layer
As can probably be inferred, action contains Struts Action classes and forms contains Struts Form beans. The action classes operate against the service interfaces to accomplish their work, with the implementation of those interfaces being wired up through Spring.
Our version control system makes it particularly painful to have to rename files and directories, so I am attempting to avoid as much of that as I can. It's one of those things where the tool impedes our willingness to refactor and revise our initial choices; I am sure many folks face that same issue. I would welcome feedback and dialog about packaging, hoping this brief writeup might serve as a catalyst and reference point for discussion.
Regards,
Our application uses a persistence layer, a domain layer, a service layer, and a presentation layer. We are currently working out the service layer/domain layer boundaries through refactoring of some rather large service objects. The packaging scheme is below; I am using a ficticious prefix to avoid any privacy issues:
Java Packaging Scheme
com.acme.application
com.acme.application.action
com.acme.application.dao
com.acme.application.dao.hibernate
com.acme.application.domain
com.acme.application.domain.logic
com.acme.application.forms
com.acme.application.resources
com.acme.application.service
com.acme.application.service.spring
Persistence Layer
dao contains interfaces for DAOs to be implemented, and dao.hibernate contains the Hibernate implementations of the interfaces.
Domain Layer
domain contains the domain objects, also referred to as business objects; just how much business logic is contained in these is an ongoing discussion. Beyond the getters and setters for the required properties, validation may be included in them. domain.logic contains interfaces and implementations of more-complex objects that manage collections and/or hierarchies of domain objects. This is somewhat similar to the structure of the jpetstore sample application, from which we took the idea for this structure.
Service Layer
service contains interfaces for service objects that group and/or manage domain.logic objects within transactional boundaries. service.spring contains the Spring implementations of those objects. This allows for other implementations, such as Pico, if need be (although highly unlikely).
Presentation Layer
As can probably be inferred, action contains Struts Action classes and forms contains Struts Form beans. The action classes operate against the service interfaces to accomplish their work, with the implementation of those interfaces being wired up through Spring.
Our version control system makes it particularly painful to have to rename files and directories, so I am attempting to avoid as much of that as I can. It's one of those things where the tool impedes our willingness to refactor and revise our initial choices; I am sure many folks face that same issue. I would welcome feedback and dialog about packaging, hoping this brief writeup might serve as a catalyst and reference point for discussion.
Regards,