2

I was going over some old code and found the following peculiar naming convention at a template method implementation.

// TEMPLATE METHOD
// Checks condition and fail fast if condition is met.
// Otherwise call the hook method (to be implemented by subclasses).
@Override
public boolean accept(String text) {
    if (condition) {
        return false;
    }

    // call to the hook method. Each subclass implements its own logic
    return acceptImpl(text);
}

// HOOK METHOD
protected abstract boolean acceptImpl(String text);

I would expect the hook method to be named doAccept() or acceptHook() instead of acceptImpl().

Is the "-Impl" suffix used in practice for hook methods?

or

Is it indeed a confusing naming practice?

1 Answers1

3

doAccept() would be definitely the more familiar convention, I think that mostly stems from the Servlet API.

I wouldn't call it confusing though, it's still easy enough to understand, and the convention it breaks is not nearly as universally expected as e.g. having uppercase class names and lowercase method and variable names.