13.10.2021 |

Template Model

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses which may differ. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure. This Pattern was identified in the book Design Patterns

Example:

public abstract class Development {

    // Skeleton algorithm of a Development Workday
    public void work() {
        drinkCoffee();
        haveAMeeting();
        
        doCode();

        talkToColleagues();
        drinkCoffee();
        haveAMeeting();
        
        doCodeReview();
    }

    // Template Method
    protected abstract void doCodeReview();

    // Template Method
    protected abstract void doCode();

    private void haveAMeeting() {
        System.out.println("lala ...");
    }

    private void talkToColleagues() {
        System.out.println("bla ...");
    }

    public void drinkCoffee() {
        System.out.println("Sip ...");
    }
}

see also https://en.wikipedia.org/wiki/Template_method_pattern

Zur Übersicht
Simon Jakubowski

Mehr vom Devsquad...

Dennis Hundertmark

Lighthouse Treemap

Jan Sauer

Monitoring Serverless Deployments on AWS Lambda

Hallo, ich bin Jörg Herbst!

Ich bin der CEO von newcubator und freue mich über jede Nachricht!

* Pflichtfeld