Wednesday, December 17, 2008

Command Pattern & Servlets

Another use of Command pattern is in the Servlet. Servlet's service method runs on a separate thread where as Servelts are singletons.
This limits the user from using instance level variables to share data among custom methods we write in the Servlet. One way to overcome this is to use command pattern. Declare the command interface and an anonymous class using the interface within the service method. Invoke the command class from within the service method.
The command object can have different methods and can access instance variables of command class.
Check out this site

No comments: