Why HttpServlet
class is declared as abstract even there is no abstract method in that class?
It's because it follows the Template Method design pattern. The doXxx()
methods have all default behaviours of returning a HTTP 405 Method Not Implemented error. If those methods were all abstract, you would be forced to override them all, even though your business requirements don't need it at all. It would only result in boilerplate code and unspecified/unintuitive behaviour.
It is declared as a class instead of an interface to implement most of the cruft/repeatable code required for setting up a servlet. It is declared as abstract
since it wouldn't make sense to instantiate a "bare bones" servlet which takes care only of the setup and doesn't contain any custom/user defined logic in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With