zoukankan      html  css  js  c++  java
  • Refactoring #002 Inline Method

    Example

        private ServerSocket createServerSocket(final int port) throws IOException {
            ServerSocket result = new ServerSocket(port);
            return result;
        }
    
        public void startup() {
            try {
                ServerSocket serverSocket = createServerSocket(PORT);
                printServerPrompt("The server is listening on " + PORT + " port ...");
                startWorking(serverSocket);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

     /

        public void startup() {
            try {
                ServerSocket serverSocket = new ServerSocket(PORT);
                printServerPrompt("The server is listening on " + PORT + " port ...");
                startWorking(serverSocket);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    Note

    为什么/何时要 Inline Method?同样是考虑代码的“代码复用”和“可读性”:

    1. 函数体本身已经有足够的表达能力、并且只被调用一次,就没必要绕多余的弯子(“间接性可能带来帮助,但非必要的间接性总让人不舒服。”
    2. 如果你手上有一群组织不合理的函数,那么先把它们集中起来再重新进行 Extract Method 应该是个很不错的主意。

    Inline Method 的手段:和 Extract Method 恰好相反

  • 相关阅读:
    shell脚本进阶
    sort与uniq命令
    sed命令
    DNS与CDN
    nginx
    Docker Private Registry
    docker存储卷
    docker容器网络配置
    docker容器网络
    docker容器虚拟化
  • 原文地址:https://www.cnblogs.com/xkxf/p/8298369.html
Copyright © 2011-2022 走看看