zoukankan      html  css  js  c++  java
  • 代码重构之移除对参数的赋值

    意图

    • 区别按值传递和按引用传递,提升代码的清晰度

    • 如果只以参数表示被传递进来的东西,代码会清晰很多

    示例

    /**
     * 移除对参数的赋值之前
     * Created by luo on 2017/4/25.
     */
    public class RemoveAssignmentsToParametersBefore {
        void discount (int inputVal, int quantity, int yearToDate){
            if (inputVal > 50){
                inputVal -= 20;
            }
        }
    }
    /**
     * 移除对参数的赋值之后
     * Created by luo on 2017/4/25.
     */
    public class RemoveAssignmentsToParametersAfter {
        void discount (int inputVal, int quantity, int yearToDate){
            int result = inputVal;
            if (inputVal > 50){
                result -= 20;
            }
        }
    }
  • 相关阅读:
    jdbc基础
    JavaScrip练习
    EL标签
    javaBean和mvc思想
    jsp
    Session
    Cookie
    ServletConfig
    c++、opencv、泊松融合
    目标检测、Iou、nms、soft_nms、
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/6765032.html
Copyright © 2011-2022 走看看