« Divert the firehose | Home | Type specific Comparators in JDK 5 »
Design smell: PleaseSirCanYouCallMyMethod
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.
About this entry
You’re currently reading “Design smell: PleaseSirCanYouCallMyMethod,” an entry on Pure Danger Tech
- Published:
- Nov 21 2006 / 2:03 pm
- Category:
- programming, design, Java
- Vote:
- Other posts with these tags:

3 Comments
Jump to comment form | comments rss | trackback uri