javadesign-patternslanguage-agnosticnomenclature

Public method calls private method with the same name - what is this pattern?


Consider this code from Apache Commons StringUtils:

public static String[] splitByCharacterType(final String str) {
    return splitByCharacterType(str, false);
}

private static String[] splitByCharacterType(final String str, final boolean camelCase) {
    // Some code...
}

This is a pretty common approach - public method delegates a call to private method with the same name but with additional parameters. Is there any name for this pattern?


Solution

  • Its more likely to be the Facade design pattern. Is more known to provide a unified interface to a set of interfaces in a subsystem. But in this case I think is used to define a higher-level implementation that makes the subsystem easier to use. As you can see the parameters are two in SplitByCharacterType(final String str, final boolean camelCase), but only one is exposed to the outer world via splitByCharacterType(final String str).

    Hiding the implementation details is also a concept of Encapsulation. So the other users are being provided with the things they need to know/use and the actual processing is left to the one responsible for it.