zoukankan      html  css  js  c++  java
  • 侵入式和非侵入式的区别

    非侵入式设计

    一个客户端的代码可能包含框架功能和客户端自己的功能。

    侵入式设计,就是设计者将框架功能“推”给客户端,而非侵入式设计,则是设计者将客户端的功能“拿”到框架中用。

    侵入式设计有时候表现为客户端需要继承框架中的类,而非侵入式设计则表现为客户端实现框架提供的接口。

    侵入式设计带来的最大缺陷是,当你决定重构你的代码时,发现之前写过的代码只能扔掉。而非侵入式设计则不然,之前写过的代码仍有价值。 

    struts1的设计是侵入式的:

    1. public class loginAction extends Action{
    2. public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws ActionException{
    3. LoginForm loginForm = (LoginForm)form;
    4. if ( "scott" .equals(loginForm.getUsername() && "tiger" .equals(loginForm.getPassword)))
    5. return mapping.findForward( "success" );}
    6. else {
    7. return mapping.findForward( "failure" );}
    8. }


    而webwork的设计则是非侵入的:

      1. public class LoginAction implements Action{
      2. private final static String LOGINFAIL = "loginfail" ;
      3. private final static String SUCCESS = "success" ;
      4. private String passward;
      5. private String username;
      6. public String getPassword(){
      7. return password;
      8. }
      9. public void setPassword(String password){
      10. this .password = password;
      11. }
      12. public String getUsername(){
      13. return username;
      14. }
      15. public void setUsername(String username){
      16. this .username= username;
      17. }
      18. public String execute() throws Exception{
      19. if ( "yeeku" .equalsIgnoreCase(getUsername())&& "password" .equals(getPassword)){
      20. ActionContext ctx= ActionContext.getContext();
      21. Map session = ctx.getSession();
      22. session.put("username" ,getUsername());
      23. return SUCCESS;
      24. }
      25. else return LOGINFAIL;
      26. }
  • 相关阅读:
    《数据结构
    《数据结构
    《数据结构
    《算法
    《linux 进程管理》- ps/top/kill/killall/nice
    《linux 字符处理》- grep/sort/uniq/tr/paste/sed/awk
    《linux 文件目录》- touch/rm/mv/cat/head/tail/cp/mkdir/chmod/chown/find/locate/which/whereis/tar
    MySQL优化必须调整的10项配置
    PV-UV
    linux+nginx+mysql+php高性能服务器搭建
  • 原文地址:https://www.cnblogs.com/bendantuohai/p/4635285.html
Copyright © 2011-2022 走看看