Skip to content

Instantly share code, notes, and snippets.

@pablohdzvizcarra
Created April 23, 2022 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablohdzvizcarra/0ca6c7b183655900ce71dffd2f370c64 to your computer and use it in GitHub Desktop.
Save pablohdzvizcarra/0ca6c7b183655900ce71dffd2f370c64 to your computer and use it in GitHub Desktop.
application a hook in a class using a method
package jvm.pablohdz.restapidesignpatterns.example.template;
public abstract class BasicEngineering {
public final void completeCourse() {
// the course must be completed in order to pass
// 1. Math
// 2. Soft Skills
// 3. Special Paper
completeMath();
completeSoftSkills();
completeSpecialPaper();
if (isAdditionalPapersNeeded()) {
completeAdditionalPapersHook();
}
}
public abstract void completeSpecialPaper();
private void completeSoftSkills() {
System.out.println("2. Soft Skills");
}
private void completeMath() {
System.out.println("1. Mathematics");
}
public void completeAdditionalPapersHook() {
System.out.println("4. Additional Papers are needed for this course.");
}
/**
* This method act how a hook, all children can be overridden this method
*
* @return true if additional papers are needed
*/
public boolean isAdditionalPapersNeeded() {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment