> I have a number of servlets in my application that need to
> perform common initialisation, etc.  So I was thinking of
> creating a superclass that has an init method that does all
> of the common work, eg.,
...snip...
> This seems to be OK, until I implement init in the
> WorkerServlet, as the init method in the SuperServlet
> does not then get invoked.  While I can call super.init()
> in the WorkServlet, I want this to be handled automatically
> as I can bet on someone forgetting this step, eg.,
>
> public class WorkerServlet extends SuperServlet {
>   public void init() {
>     // don't want to have to make this call ==> super.init();
>   } // init
>   ...
> } // WorkerServlet
>
> Is there any way to implement this ?

Answer 1: No
----

Answer 2: But wait, you can make the init() method in SuperServlet FINAL.
Then when someone tries to overide init(), the compiler will say no.

Now add empty methods
initExtend() and initExtend(ServletConfig c) to the base class.

Call these methods _last_ in SuperServlet's init methods.

Document that derived classes should implement these methods if they require
additional initialization.  With this approach the mistake cannot be made.

nite,
Jim


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to