首先请看如下的代码。 view plainprint? q8 q/ b8 k5 ]1 b class Help { private int n;Help() { this.n = 0;} public void setMe(int n) { Helper.setValue(this, n);} public void setN(int n) { this.n = n;}. p7 d$ Q! s' j* ~9 R7 O j
class Helper { static public void setValue(Help h, int n) { h.setN(n);}' y$ p* h# W6 I/ z
public class TestQuestion{ public static void main(String[] args) { Help h = new Help();h.setMe(13);} 2 w' B9 M5 R* P Help的setMe体例挪用了Helper的setValue体例,Helper的setValue体例又挪用了Help的setN体例。这样似乎中心的Helper没有用。可是它可以加一些检测操作,使得这种检测操作分手出来。具体如下:view plainprint? # a) ~0 v( `; ~1 ^- f+ j class Help { private int n;Help() { this.n = 0;} public void setMe(int n) { Helper.setValue(this, n);} public void setN(int n) { this.n = n;}6 _" g! U( p& f: ]2 d9 p
class Helper { static public void setValue(Help h, int n) { if (n < 1000) { h.setN(n);} else { System.out.println("The value is beyond 1000.");} , n- c1 o- b1 X& z8 h public class TestQuestion{ public static void main(String[] args) { Help h = new Help();h.setMe(13);} o2 `3 @ S+ g! q& x7 r* q2 L2 n
这样可以把检测分手出来,合适软件工程团队开发的的思惟。