I'm sure this question gets asked all the time, so please bear with me.
I am creating an online store for our company. As part of the design, I wanted to seperate the admin/back-office functions into a seperate webapp. The admin webapp will be located on our local company intranet. My question is about how to best design this in terms or servlets/ejb. Since both the storefront and the admin apps will share many of the same functions, if I create seperate webapps, I will be copying a lot of the same code into both apps. I have never used EJBs before, but it seems like if I put these shared functions into EJBs, I could then just call these functions from both my storefront and admin apps without having to copy any code?
Using this logic, it seems like EJBs are the only way to go to share code? Is that correct? Has anyone worked on a similar project that can offer any advice?
Bob, it all depends on how you code your application, or better yet, how you design your application. Frameworks like Struts and JSF are designed to seperate presentation from business logic and data access from both. For data access, I highly recommend using Hibernate, an Object Relational Mapping framework, that is highly decoupled from your business logic. By using techniques like this you can better create reuse in the business logic and data access sections of your code.
What this means is that EJB isn't the only way to go, actually i would say it is probably the more complicated way to go.
Another framework to look into that is less complicated than EJBs is the Spring framework/container, this way you can use plain old Java objects instead of EJBs and still get the benefits of an App Server for transactions, security, etc. And you only need to add what you need and not any more.
Currently I am planning on using WebWork/Velocity/Hibernate in the app. I am just concerned about creating a method, then having to copy it to both my storefront app and admin app. This leaves open the chance of human error by not copying the same version of the method to both apps. If both apps could pull the method from a central location, everything seems to be solved.
subject: Servlet or EJB design question for Online Store