Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How use OOPs in Servlet

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How we are using OOP consept in Servlet code design. Where is inheritance and Polyformisam.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet is the best example of OOP. Your web application is usually a number of screens, most of screens have something in common, some screens look similar to others. So you do the following:
1. define a base servlet taking care of common content and behavior of all screens
2. inherit servlets from the base to serve particular screens
3. build more complex hierarchy for servlets servicing similar screens, like reports, form processor and so on.
Using OOP reduces amount of developed code drastically. You need just override a few functions of base servlet and get completely different behavior. It's very powerful approach.

Maybe I should write a book about that, who knows?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The actual servlet spec and classes are a small part of an application. You can apply OO Design Principles to your systems whether you start from a servlet framework or not. Read up on those principles and see the kinds of things we tend to care about.

If those make good sense, google for "MVC model 2" which is recipe for separating the responsibilities of servlets, JSP pages and a Plain Old Java Object business model.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wish to add this.

By overriding the service method itself you are doing dyanamic polymorphism.
Of course, this is achieved by none other than polymorphism.

Learning the OOPs concepts thoroughly and analysing how it is implemented in different Java technology will help you a lot
 
Not so fast naughty spawn! I want you to know about
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic