EJB design: design question
Is it a good practice to have one stateless session ejb with 4 public and 30 private methods which does all the business processing and the code runs to 3500 lines
Break the business process into four sub classes and call the classes from one single ejb. The scope of the four classes will be protected.
which scenario is best????
is there any better design than both of them.
I'd approach the problem differently. Come up with a sensible object or component oriented model for your system and then implement it. Yes, lines of code can be an indicator you're not being modular enough, but as I say, address the problem differently.
See, you are talking about design.
Definitely, approach 2. Moreover, these are (or should be) not a "sub classes" but a major classes in your program that implements BUSINESS LOGIC. SLSB is just a wrapper to expose the logic to "remote" world.
In ideal world, you could just design your system as it should behave without any respect to technology (EJB in this case). Yes, I know, there are numerous issues associated with approach above (like what if logic classes have to access data, security concerns, transactional behavior etc). So there is a real chance to make a code polluted with calls to technology-specific API. I recommend to use most applicable for your needs IoC framework (my own preference is Spring) to isolate your business logic from technology details.
Manageability & testability benefits of approach 2 not mentioned here just for brevity :-)
I use a strategy of using helpers which have specific purpose of encapsulating certain functionality that the EJB needs.
This will promote not only ease of maintenance(less lines of code in files) but also abstraction(details of some methods goes into helpers), flexibility(helpers can grow independently) and reuse(some methods in the helpers might be used by other EJB's).
Let me know if you need to discuss your specific case, and will be happy to help.
You can also email at email@example.com