This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How use OOPs in Servlet

 
kamlesh tayade
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.
 
dema rogatkin
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?
 
Stan James
(instanceof Sidekick)
Ranch Hand
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.
 
Sarath Mohan
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic