Typically, a hook is an non-abstract method defined in an abstract class, that can be optionally implemented and overridden in subclasses to modify behaviour. I think this is best exemplified in the template method pattern, where the (abstract) superclass defines the overall semantics for a process, but leaves primitive operations to be implemented by sublasses:
A template method is defined inside an abstract class:
public abstract class AbstractLogger {
/*
* Template method, made final to make
* sure the flow is not modified by subclasses
*/
public final void logMessage(String msg) {
msg = preProcess(msg);
writeToLog(msg);
}
/*
* Abstract primitive operation that must be
* implemented by subclasses
*/
protected abstract void writeToLog(String str);
/*
* Hook method that can be optionally overriden to
* modify the template method's behaviour
*/
protected String preProcess(String str) {
return str; // default behaviour: do nothing
}
}
Concrete subclasses make use of the hook-method to augment behaviour:
public abstract class TerminalLogger extends AbstractLogger {
/*
* This primitive operation must be implemented
*/
protected void writeToLog(String str) {
System.out.println(str);
}
/*
* Override super.preProcess() to modify behaviour
* of the template method
*/
protected String preProcess(String str) {
return str.toLowerCase();
}
}
Pardon the contrived example - I hope it illustrates the point clearly enough.
For more info on hook methods and template methods see:
http://en.wikipedia.org/wiki/Hook_method#Hook_methods
http://en.wikipedia.org/wiki/Template_method_pattern
The template method pattern wiki presents a fuller example than mine - you might want to check it out.