This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I've been asked to look into the Web-State Pattern for some JSP / servlet work I'm about to start ... is this the same as the MVC pattern? from what I understand both make use of JSPs (view) JavaBeans & Servlets (model & controller). Has anyone done any development using this pattern? How does it essentially work?
Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
It may be related to the "State" pattern in GoF (always worth a re-read for any patter question). In the State pattern, the state of a process is represented by an instance of a class which implements an interface (or extends a particular base class). To change state, simply replace the state object with another object. The code using the state object neither knows or cares which state it is in. For a web-specific use you might have a single JSP in which a named bean represents the state. Either in the JSP or in one or more associated servlets, you could make sure that the correct bean is in the session ready for the JSP each tim eit is called. Does this make sense?
MVC-State Pattern is actually is the combination of MVC and State patterns. Main idea is based on a servlet that acts like a controller to get the requests from the web clients and delegate it to the model. So far it is pure MVC. The effect of State pattern comes when your model have different states and all these states are represented with different JSP. So the Context in the State pattern of GOF corresponds to the servlet itself. It sends the requests to State interface and depending upon the state which your state-dependent object is the servlet redirect the response to a different JSP, which is specificaly designed for that state. In this scenario, of course your servlet should know about which state is active. Akin Kaldiroglu
Joined: Mar 02, 2000
Ok I finally got some documentation on this from someone here ... essentially it's a combination of state and MVC patterns. The JSP being the view, Javabeans handle the model and we have controller Servlets there is also a state class which handles the state so the controller Servlet doesn't need to know the state .. it receives an HTTP request and invokes processRequest() on the instance of the State calss in the Session profile. i think that's it ... the document is quite confusing I'll need to read through it again!