These methods hook cited are used in the Template pattern. Just as the excerpt you quoted mentions, there is an abstract class A
that delegates parts of its functionality to abstract methods. A concrete class B
that inherits from this class need to implement these methods so that the code Compile. See 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
}
}
That way, you know you can call acaoPersonalizada
in any copy of the class MinhaClasseAbstrata
that there will be a guaranteed return, based on the definition of porcaoPersonalizada
of the specific type of the object in question.
You could put an excerpt from the material that quotes this?
– Pablo Almeida
@Pablo Ai is the passage.
– Pena Pintada
Got it. I’m writing the answer.
– Pablo Almeida