From the course: Java Design Patterns: Structural
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Challenge: The Decorator pattern - Java Tutorial
From the course: Java Design Patterns: Structural
Challenge: The Decorator pattern
(upbeat music) - [Woman] Let's have a look at our next challenge. This challenge is to refactor a pizza ordering app. The app has a interface called Pizza which defines two methods called Get Toppings and Get A Name. There are then three classes that implement pizza, called Pizza Hawaiian, Pizza Margherita and Pizza Peperoni. Each of these classes adds toppings to the list in the constructor. For example, in the Pizza Peperoni class, in the constructor I'm adding cheese, tomato and pepperoni. In the main class, there is a method called Order, that takes a pizza as an argument. This prints out what pizza you've ordered, and what the toppings are. In the main method, three orders are placed, one for a Margherita Pizza, one for a Hawaiian Pizza, and one for a Pepperoni Pizza. If I run the app, I can see it print out of the console, the pizzas that I've ordered. It shows me that I've ordered a Margherita, a Hawaiian and a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.