Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:重复,过度使用——问题?_Java_Coding Style_Repeat_Overuse - Fatal编程技术网

Java:重复,过度使用——问题?

Java:重复,过度使用——问题?,java,coding-style,repeat,overuse,Java,Coding Style,Repeat,Overuse,我尽可能地做一个极简主义者。重复是个问题。我讨厌它。什么时候才是真正的问题 什么是静态过度使用 什么是现场方法过度使用 什么是班级过度使用 是否有更多类型的过度使用 问题A:当使用静电太多时? private static class Data { private static String fileContent; private static SizeSequence lineMap; private s

我尽可能地做一个极简主义者。重复是个问题。我讨厌它。什么时候才是真正的问题

  • 什么是静态过度使用
  • 什么是现场方法过度使用
  • 什么是班级过度使用
  • 是否有更多类型的过度使用
  • 问题A:当使用静电太多时?

        private static class Data
        {
                private static String fileContent;
                private static SizeSequence lineMap;
                private static File fileThing;
                private static char type;
                private static boolean binary;
                private static String name;
                private static String path;
        }
    
        private static class Print
        {
                //<1st LINE, LEFT_SIDE, 2nd LINE, RIGHT_SIDE>
                private Integer[] printPositions=new Integer[4];                
    
                private static String fingerPrint;
                private static String formatPrint;
    
        }
    
        public Stack<Integer> getPositions(){return positions;}
        public Integer[] getPrintPositions(){return printPositions;}
    
    
        private Stack<String> getPrintViews(){return printViews;}
        private Stack<String> getPrintViewsPerFile(){return printViewsPerFile;}
        public String getPrintView(){return printView;}
    
        public String getFingerPrint(){return fingerPrint;}
        public String getFormatPrint(){return formatPrint;}
    
    
        public String getFileContent(){return fileContent;}
        public SizeSequence getLineMap(){return lineMap;}
        public File getFile(){return fileThing;}
        public boolean getBinary(){return binary;}
        public char getType(){return type;}
        public String getPath(){return path;}
    
        public FileObject getData(){return fObj;}
        public String getSearchTerm(){return searchTerm;}
    
    私有静态类数据
    {
    私有静态字符串文件内容;
    私有静态尺寸序列线图;
    私有静态文件;
    私有静态字符类型;
    私有静态布尔二进制;
    私有静态字符串名;
    私有静态字符串路径;
    }
    私有静态类打印
    {
    //
    私有整数[]printPositions=新整数[4];
    私有静态字符串指纹;
    私有静态字符串格式打印;
    }
    
    问题B:当使用私有方法获取字段数据太多时?

        private static class Data
        {
                private static String fileContent;
                private static SizeSequence lineMap;
                private static File fileThing;
                private static char type;
                private static boolean binary;
                private static String name;
                private static String path;
        }
    
        private static class Print
        {
                //<1st LINE, LEFT_SIDE, 2nd LINE, RIGHT_SIDE>
                private Integer[] printPositions=new Integer[4];                
    
                private static String fingerPrint;
                private static String formatPrint;
    
        }
    
        public Stack<Integer> getPositions(){return positions;}
        public Integer[] getPrintPositions(){return printPositions;}
    
    
        private Stack<String> getPrintViews(){return printViews;}
        private Stack<String> getPrintViewsPerFile(){return printViewsPerFile;}
        public String getPrintView(){return printView;}
    
        public String getFingerPrint(){return fingerPrint;}
        public String getFormatPrint(){return formatPrint;}
    
    
        public String getFileContent(){return fileContent;}
        public SizeSequence getLineMap(){return lineMap;}
        public File getFile(){return fileThing;}
        public boolean getBinary(){return binary;}
        public char getType(){return type;}
        public String getPath(){return path;}
    
        public FileObject getData(){return fObj;}
        public String getSearchTerm(){return searchTerm;}
    
    public Stack getPositions(){return positions;}
    公共整数[]getPrintPositions(){return printPositions;}
    私有堆栈getPrintView(){return printview;}
    私有堆栈getPrintViewsPerFile(){return printViewsPerFile;}
    公共字符串getPrintView(){return printView;}
    公共字符串getFingerPrint(){return fingerPrint;}
    公共字符串getFormatPrint(){return formatPrint;}
    公共字符串getFileContent(){return fileContent;}
    公共大小序列getLineMap(){return lineMap;}
    公共文件getFile(){return fileThing;}
    公共布尔getBinary(){return binary;}
    public char getType(){return type;}
    公共字符串getPath(){return path;}
    public FileObject getData(){return fObj;}
    公共字符串getSearchTerm(){return searchTerm;}
    
    相关的

    是否有更多类型的过度使用

    是的。。。教条主义的过度使用

    您需要平衡地理解何时适合使用这些构造(静态、字段、方法、类、接口等),何时不适合。简单地试图避免使用某些构造显然是错误的

    例如,但是静态字段有一个问题,即整个JVM中只能有一个字段实例。这意味着使用静态的代码往往是不可重入的,这会使它在很多情况下不可用;e、 g.当涉及多个线程或递归时。然而,在某些情况下,您需要在整个JVM中只有一个实例,在这些情况下,静态是完全可以接受的

    (以上是对静力学问题的过度简化。我试图说明你应该如何思考这些事情。了解利弊,并根据每个案例的是非曲直来判断,而不是根据你在某处听到/读到的教条。)

    “仅仅因为你可以,并不意味着 你应该这样!”

    如果您打算在代码中做或不做某些事情(例如,静态字段、私有访问器、接口),我认为最简单的答案是有充分的理由采取这种立场。盲目地遵循“规则”是一个错误,如果没有人有足够的勇气更改代码,通常会造成维护噩梦。最好说,“我使用私有访问器是因为它给了我X,例如,我可以对所有数据访问/修改强制序列化”,但如果在所有类中使用私有访问器不能实现任何实际的功能,那么可能会造成过度杀伤力和时间浪费。

    @HH:static==通常会使测试更加困难。有人可能会错误地认为,因为在实际的程序中,在整个JVM中,您只需要一个实例,那么静态就可以了。然而,一旦有人决定需要执行“在此处插入您最喜欢的测试类型”,这种短视将会严重影响。永远记住:像约书亚·布洛赫和道格·利亚这样的人物比那些拥有4或5位数重复次数的人更具权威性;)