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:
“A hook shot kisses the rim and
hangs there, helplessly, but doesnt drop
and for once our gangly starting center
boxes out his man and times his jump
perfectly, gathering the orange leather
from the air like a cherished possession”
—Edward Hirsch (b. 1950)
“The philosopher is in advance of his age even in the outward form of his life. He is not fed, sheltered, clothed, warmed, like his contemporaries. How can a man be a philosopher and not maintain his vital heat by better methods than other men?”
—Henry David Thoreau (18171862)