JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Software Design  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 [討論]一致的流程,只有相依物件不同如何設計?
caterpillar

良葛格

版主

發文: 2613
積分: 70
於 2005-04-28 10:21 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我有兩個方法,流程完全一致,但其中有個platform物件不同而已,如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  public boolean doWebMVC(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception {
 
        String actionKey = webPlatform.getActionKey(servletRequest, servletResponse);
 
        ActionGroup actionGroup = getActionGroup(actionKey);
 
        Map command = webPlatform.processCommand(servletRequest, servletResponse, actionGroup);
 
        Map model = webPlatform.processModel(servletRequest, servletResponse, actionGroup);
 
        String failView = validateCommand(command, model, actionGroup);
        
        if(failView!= null) {
          webPlatform.processModelAndView(servletRequest, servletResponse, model, failView);
          return false;
        }
             
    String view = processAction(command, model, actionGroup);
    
    webPlatform.processModelAndView(servletRequest, servletResponse, model, view);
    
    return true;
  }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  public boolean doMVC(Object request, Object response) throws Exception {
 
        String actionKey = platform.getActionKey(request, response);
        
        ActionGroup actionGroup = getActionGroup(actionKey);
      
        Map command = platform.processCommand(request, response, actionGroup);
 
        Map model = platform.processModel(request, response, actionGroup);
 
        String failView = validateCommand(command, model, actionGroup);
        
        if(failView!= null) {
          platform.processModelAndView(request, response, model, failView);
          return false;
        }
             
    String view = processAction(command, model, actionGroup);
    
    platform.processModelAndView(request, response, model, view);
    
    return true;
  }


IWebPlatform物件是這樣的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package onlyfun.caterpillar.mvc;
 
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import onlyfun.caterpillar.core.ActionGroup;
 
public interface IWebPlatform {
  public String getActionKey(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception;
  public Map processCommand(HttpServletRequest servletRequest, HttpServletResponse servletResponse, ActionGroup actionGroup) throws Exception;
  public Map processModel(HttpServletRequest servletRequest, HttpServletResponse servletResponse, ActionGroup actionGroup) throws Exception;
  public Object processModelAndView(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Map model, String view) throws Exception;
}


而IPlatform是這樣的:
1
2
3
4
5
6
7
8
9
10
11
12
package onlyfun.caterpillar.mvc;
 
import java.util.Map;
 
import onlyfun.caterpillar.core.ActionGroup;
 
public interface IPlatform {
  public String getActionKey(Object request, Object response) throws Exception;
  public Map processCommand(Object request, Object response, ActionGroup actionGroup) throws Exception;
  public Map processModel(Object request, Object response, ActionGroup actionGroup) throws Exception;
  public Object processModelAndView(Object request, Object response, Map model, String view) throws Exception;
}


我想過只使用doMVC()那個方法,只要在IPlatform的每個方法中對request、response作Cast就可以了,但Cast會帶來效率負擔。

我想過用Strategy模式,直接讓IPlatform的實例包括HttpServletRequest、HttpServletResponse,但因為是在Web多執行緒環境下,所以使用Strategy模式必須每一次處理都產生一個IPlatform的實例。

為了不作Cast、不在每一次處理時產生實例,目前我想到的是就是最上面的兩個流程,但這又造成日後維護的不便,只要改動doMVC()或doWebMVC(),另一個就要跟著改變。

效率、資源與維護的取捨,這樣的情況下,請問有什麼好的設計方式。。。。?Shy


reply to postreply to post
良葛格學習筆記
話題樹型展開
人氣 標題 作者 字數 發文時間
3569 [討論]一致的流程,只有相依物件不同如何設計? caterpillar 3485 2005-04-28 10:21
2992 Re:[討論]一致的流程,只有相依物件不同如何設計? jd001982 138 2005-04-29 05:14
3074 Re:[討論]一致的流程,只有相依物件不同如何設計? caterpillar 2634 2005-04-29 09:07
4235 Re:[討論]一致的流程,只有相依物件不同如何設計? plutotw 597 2005-04-29 09:31
2963 Re:[討論]一致的流程,只有相依物件不同如何設計? caterpillar 896 2005-04-29 09:58
2928 Re:[討論]一致的流程,只有相依物件不同如何設計? plutotw 133 2005-04-29 10:21
2937 Re:[討論]一致的流程,只有相依物件不同如何設計? caterpillar 652 2005-04-29 10:55
2926 Re:[討論]一致的流程,只有相依物件不同如何設計? plutotw 68 2005-04-29 11:22
4185 Re:[討論]一致的流程,只有相依物件不同如何設計? alien 291 2005-04-29 15:04
2918 Re:[討論]一致的流程,只有相依物件不同如何設計? caterpillar 143 2005-04-29 16:55
2946 Re:[討論]一致的流程,只有相依物件不同如何設計? jd001982 1619 2005-04-30 03:07
2915 Re:[討論]一致的流程,只有相依物件不同如何設計? leonz 0 2005-05-02 00:55
2972 Re:[討論]一致的流程,只有相依物件不同如何設計? caterpillar 80 2005-05-02 09:34
3134 Re:[討論]一致的流程,只有相依物件不同如何設計? caterpillar 174 2005-05-03 11:41
» JWorld@TW »  Software Design

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8