• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why an inner class?

 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Choon-Chern. That's a useful link!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic