首先请看如下的代码
view plainprint?
class Help { private int nHelp() { thisn = } public void setMe(int n) { HelpersetValue(this n)} public void setN(int n) { thisn = n}
class Helper { static public void setValue(Help h int n) { hsetN(n)}
public class TestQuestion{ public static void main(String[] args) { Help h = new Help()hsetMe()}
Help的setMe方法调用了Helper的setValue方法Helper的setValue方法又调用了Help的setN方法这样似乎中间的Helper没有用但是它可以加一些检测操作使得这种检测操作分离出来具体如下view plainprint?
class Help { private int nHelp() { thisn = } public void setMe(int n) { HelpersetValue(this n)} public void setN(int n) { thisn = n}
class Helper { static public void setValue(Help h int n) { if (n < ) { hsetN(n)} else { Systemoutprintln(The value is beyond )}
public class TestQuestion{ public static void main(String[] args) { Help h = new Help()hsetMe()}
这样可以把检测分离出来符合软件工程团队开发的的思想