The ln project was completely completed as of yesterday, with no functional implementation problems. However, there are still many other problems in the "premature infants" coming out this week, for example, the Code repetition is too high and the coupling between classes is too large. Although the layered approach is used in the entire system, The bll-Layer Code is basically the same, that is to say, if the demand changes (such as adding a Department for review, or the original department review order is adjusted) the entire BLL layer needs to be changed.
The architecture of the entire system is as follows:
The overall architecture is fine, classic MVC. In fact, the system this time is a little different. The macro view is MVC, but we have gone through the model layer. net, which leads to each servlet corresponding to its own Bll, resulting in too many duplicate code at the BLL layer.
Duplicate code (repeated Code) is one of the bad tastes of code ("Bad taste of code"-reference from refactoring).
So ......
Through the analysis of the entire ln system, we can see that this system is a responsibility chain. First, the user fills in the application information, and then the application is approved at the level of each department, it is finally approved (or rejected ). Although it is not the same as the responsibility chain model in the classic design model, it does not affect the restructuring of the system using the responsibility chain model.
Try to use the responsibility chain mode to reconstruct the partial classification chart after The bll layer, for example:
Based on the signing opinions of various departments obtained from the database, assign these opinions to the entity class. Based on these opinions, determine whether the application has been reviewed by those departments and whether the application has passed the review. The simplified code does not involve the code of dal and sqlhelper. The result is printed and output only. The core code is as follows:
Public class Chain {public static void main (string Arg []) {// construct the class of each department (level) abstracbll levelone = new levelone (); abstracbll leveltwo = new leveltwo (); abstracbll levelthree = new levelthree (); // sets the levelone relationship between different departments. setmanager (leveltwo); leveltwo. setmanager (levelthree); // instantiate the application class (instantiate the object class) entityapplication enapplication = new entityapplication (); enapplication. suggestion1 = "agree"; enapplication. suggestion2 = "agree"; enapplica Tion. suggestion3 = "agree"; // start with the lowest level Department to determine whether the application can pass levelone. apply (enapplication) ;}}// abstract B-layer class abstract class abstracbll {protected abstracbll level; // The requested abstract method public abstract void apply (entityapplication application ); // set public void setmanager (abstracbll level) {This. level = level; }}// class levelone extends acbll {public void apply (entityapplication application) corresponding to level 1 Department {// determine whether the first-level signing opinion is consent, transfer to the next level if agreed Otherwise, the application is rejected if (application. suggestion1 = "agree") {system. out. println ("Level 1 consent"); level. apply (application);} else {system. out. println ("rejected by Level 1! ") ;}}// Class leveltwo extends abstracbll {public void apply (entityapplication application) {If (application. suggestion2 = "agree") {system. out. println ("Level 2 consent"); level. apply (application);} else {system. out. println ("rejected by Level 2! ") ;}}// Class levelthree extends abstracbll {public void apply (entityapplication application) {// determines whether the last level has passed the review, if the application is approved, it indicates that the application is not approved at the last level. suggestion3 = "agree") {system. out. println ("Level 3 consent, this review passed! ");} Else {system. Out. println (" was rejected by Level 3! ") ;}}// The applied entity class entityapplication {Public String suggestion1; Public String suggestion2; Public String suggestion3 ;}
The running result is as follows:
After reconstruction, if the system adds or adjusts the review sequence of the Department on the basis of the original one, you only need to add the BLL class or adjust the sequence of calls to the BLL layer in the servlet. In this way, you do not need to change the entire B layer, and you can clearly see that when the servlet calls Bll, you only need to manipulate the first chain in the entire responsibility chain, instead of having a relationship with other classes,This greatly reduces coupling, improves code reusability, and facilitates later maintenance.(The blue part is object-oriented ).