aspose file tools*
The moose likes Servlets and the fly likes Why an inner class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why an inner class?" Watch "Why an inner class?" New topic
Author

Why an inner class?

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
This is one of the versions of BeeServlet from the CattleDrive assignments on Servlets. I'm planning on using this as the model for my code, but I'm wondering why Default is coded as an inner class. (Though I'm copying, I figure I should still know why I'm doing what I'm doing!)

package com.javaranch.drive ;

import com.javaranch.common.* ;

public class BeeServlet extends ActionServlet
{

private class Default implements ActionHandler
{
public void doAction( ServletData servletData )
{
servletData.setAttribute( "text" , "MVC2-buzz-buzz ..." );
forward( "/bee.jsp" , servletData );
}
}

public void init()
{
addActionHandler( "default" , new Default());
}

}

If Default was moved outside of BeeServlet, would it make any difference?
Choon-Chern Lim
Ranch Hand

Joined: Aug 29, 2005
Posts: 74
http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Thanks Choon-Chern. That's a useful link!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why an inner class?