Clone Method

Here's a question that's been nagging me: Regarding OnceAndOnlyOnce, aren't there times when parellel code it a protection? If I develope a routine for use by a bigger routine, then want to make the smaller routine more widely available, I have found it wise to keep the original routine private and create a public copy. That way I don't have to worry the future changes to the (now public) routine made in support of the "bigger" routine it was created to support, will have side effects due to it's public use. Or are way talking about something else? - Cregg Hardwick


Better to clone the method only when you need to. Don't do it now just because you might need to later.

  public class Foo {
    public void a() {return b();}
    private int b() {return 1;}
  }

Now I decide to make b public. Don't clone it yet:

  public class Foo {
    public void a() {return b();}
    public void b() {return 1;}
  }

Later, I discover that the semantics of b need to change, but only as far as a is concerned. b needs to remain the same to the users of the class. Now is the time to clone b:

  public class Foo {
    public void a() {newB();}
    public void b() {return 1;}
    private void newB() {return 2;}
  }


EditText of this page (last edited September 3, 2009) or FindPage with title or text search