June 2018
Intermediate to advanced
280 pages
7h 46m
English
The template method can be implemented to allow the injection of specific method calls when the template offers the order of calls. In the following examples, we will add specific calls and set their content from outside. They may have specific content already inserted. The code can be simplified by using a single method that received all the runnables:
jshell> class TemplateMethod {...> private Runnable call1 = () -> {};...> private Runnable call2 = () -> System.out.println("Call2");...> private Runnable call3 = () -> {};...> public void setCall1(Runnable call1) { this.call1 = call1;}...> public void setCall2(Runnable call2) { this.call2 = call2; }...> public void setCall3(Runnable call3) { this.call3 = call3; }...> public ...Read now
Unlock full access