Hook Methods
Hook methods are defined in abstract classes and called from a template method. Hooks are used as placeholders that can be supplied by the component's client in a concrete derived class. Here is a Java example:
/** */ public abstract class Beverage implements Beveragelike { /** * Adds condiments to the beverage */ public abstract void addCondiments; /** * Hook method that determines whether the customer wants condiments * or not. Can be overridden. * @return true, if the customer wants condiments, and false otherwise. */ public boolean customerWantsCondiments { return true; } /** * Prepares the beverage according to this recipe. */ public final void prepareRecipe { // … if (customerWantsCondiments) { addCondiments; } } }Read more about this topic: Method (computer Programming)
Famous quotes containing the words hook and/or methods:
“... with her shoulders as bare as a building,
with her thin foot and her thin toes,
with an old red hook in her mouth,
the mouth that kept bleeding
into the terrible fields of her soul . . .”
—Anne Sexton (19281974)
“Parents ought, through their own behavior and the values by which they live, to provide direction for their children. But they need to rid themselves of the idea that there are surefire methods which, when well applied, will produce certain predictable results. Whatever we do with and for our children ought to flow from our understanding of and our feelings for the particular situation and the relation we wish to exist between us and our child.”
—Bruno Bettelheim (20th century)