These methods hook are used in the Template template. Just like the excerpt you mentioned mentions, there is an abstract class A
that delegates parts of its functionality to abstract methods. A concrete% class of% inheriting from this class must implement these methods for the code to compile. Here's an example:
public abstract class MinhaClasseAbstrata {
public abstract int porcaoPersonalizada(String parametro);
public int acaoPrincipal(String parametro) {
return parametro.length() + porcaoPersonalizada(parametro);
}
}
public MinhaClasseConcreta extends MinhaClasseAbstrata {
public int porcaoPersonalizada(String parametro) {
return parametro.length() + 55; // um cálculo qualquer específico para esse caso
}
}
public MinhaOutraClasseConcreta extends MinhaClasseAbstrata {
public int porcaoPersonalizada(String parametro) {
return parametro.length() + 23; // um cálculo qualquer específico para esse caso
}
}
In this way, you know that you can call B
on any copy of class acaoPersonalizada
that there will be a return, based on the definition of MinhaClasseAbstrata
of the concrete type of the object in question.