Thanks Damanjit.
I went through the
Sun Tutorial (Lesson 1 and 2) with a fine tooth comb and I am still not convinced. This is why:
The example shown is a simple web application which calculates a bonus. A simple client sends the social security number and multiplier via a HTTP Browser. This is made with both Servlets and EJBs, and I compared both.
Lesson 1 - Servlets
Lesson 2 - Same as Lesson 1 but with EJBs.
Lesson 1 The "business logic" in the servlet is a simple 2-line method "calculateBonus". This is very simple to understand and in my opinion, to maintain.
On compile, you only have one class:
BonusCalculationServlet.java No problem, everything works, the code is simple to read and you can continue to add more business logic as you need to.
Lesson 2 Suddenly, with the EJB variant, all hell breaks loose. You must create SIX different classes. This implements that, an interface for this, a context for that and so on. Remember, the
business logic method is 2 lines in the servlet and we finished with one simple class.
On compile with EJB, you get:
-BonusCalculationServlet.java
-BonusCalculator.java
-BonusCalculatorHome.java
-LocalBonusCalculator.java
-LocalBonusCalculatorHome.java
-BonusCalculatorBean.java
So all in all, I know which "method" I would choose. EJB just seems to add an unneccessary tier of more classes and interfaces for very little return. Whats wrong with creating a simple BonusCalculator.java class with "calculate()"? The servlet can then create an instance of this object and invoke the method when it has all the data it needs. Clean simple code that is easy to understand. The business logic is moved outside the servlet, which is what EJBs try to accomplish right?
Now someone convince me that I am wrong.
[ January 30, 2005: Message edited by: Kashif Riaz ]
[ January 30, 2005: Message edited by: Kashif Riaz ]