From the course: Java Design Patterns: Behavioral Part 2

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Implementing the Template Method pattern

Implementing the Template Method pattern - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 2

Start my 1-month free trial

Implementing the Template Method pattern

- [Instructor] In this example, I have an app that's used to create different types of pizza. There are some problems with how this app is structured at the moment, so I'm going to refactor it to use the template method button. So this app has a class called vegetarian pizza. In here, I have three methods called make base, adds toppings, and cook, which are the three steps for making the pizza. In each of these methods, I'm just printing out to the console what's happening in each step. So in the make based method, I'm just printing out mix flour, yeast, and salts, and then roll out the dough. And then in the add toppings method, I'm printing out each of the toppings I want on the pizza. So I'm adding tomato, cheese, peppers, and olives. And then in the cook method, I'm just printing out say cook in the oven for 15 minutes. Then finally I have one more method called print instructions, which calls each of the…

Contents