Pure Danger Tech


Design smell: PleaseSirCanYouCallMyMethod

21 Nov 2006

Occasionally I see methods like this:

public static void pleaseSirCanYouCallMyMethod(Thing thing, Arg1 arg1, Arg2 arg2) {
    thing.myMethod(arg1, arg2);

Basically the caller gives an object and some args to a method which calls the method with those args, which the caller could have done all by himself. This is usually a symptom of bad design or a need for more refactoring.

Sometimes instead of a static method, you’ll see a bunch of these in a class using delegation. Generally if class A holds a reference to B and has a bunch of methods that duplicate methods in B and just delegate to them, this is a smell that class responsibilities are not well-defined. Rather than having the caller go through A to get to B, maybe he should just be calling B directly. Or there should be a common interface or base class. Or maybe the classes should merge.

In general, if you see methods that do nothing but forward a call to another method, then that method is typically adding little to no value.