Suppose that we have a page flow JSP1->JSP2->...->JSPn refering to a use case UC1, realized according to MVC pattern; the flow of the pages is managed by a servlet S1.
- Posted by: Antonio Merico
- Posted on: March 26 2004 12:05 EST
Suppose that we have to implement an other use case UC2 with flow page J1->J2->...Jx->JSP1->JSP2->...JSPn->Jx+1->...Jm, which "include" the complete flow page of the use case UC2.
We have two possible ways in proceeding:
1. according to pattern MVC I realize a servlet S2 wich invoke all the page J1, ..., Jx, JSP1, ..., JSPn, Jx+1, ..., Jm. In these case I reuse all the JSP page but I must to "copy and paste" from the servlet S1 in servlet S2 all the code which manages pages JSP1, JSP2, ..., JSPn
2. I realize S1 in a way that can be "completely" reused and I realize S2 which manage the flow of the page Ji and only calls S1 which control the flow JSP1, JSP2, ..., JSPn
Which is the better solution for implementing UC1 and UC2?
In these case I reuse all the JSP page but I must to "copy and paste" from the servlet S1 in servlet S2 all the code which manages pages JSP1, JSP2, ..., JSPn2.Whatever you do, don't cut and paste. This will give you two points of maintenance for the flow of UC1, and violates the "DRY" (Don't Repeat Yourself) principle.
Many MVC frameworks use XML Config files to maintain their flow. Do this if you can.
If your flows are hard-coded into servlets, at the very least split the flow logic for servlet S1 into a separate method. Make servlet S2 a subclass of S1 and reuse that method.
Dear Mr. Strack, I thank you for your interest.
Can you suggest me some MVC frameworks that use XML Config files to maintain the flow?
Pretty much all of them, actually. (At least, all of the major ones).
If your application is pretty workflow intensive, try WebWork. Of the most popular web frameworks, this is the most "workflowish".