Adding pizzas

Now, let's add the ability to add a pizza to our order, as well as configure it:

  1. First, we'll create a Topping class, which will be contained within our Pizza class:
sealed class Topping(name: String): Item(name)object Pepperoni : Topping("Pepperoni")object Olive : Topping("Olive")object Pineapple : Topping("Pineapple")
  1. Now, we'll add a Pizza class:
sealed class Pizza(name: String) : Item(name) {    val toppings: MutableList<Topping> = mutableListOf()}

This Pizza class extends Item and has a field, MutableList<Topping>, for storing our pizza toppings. 

  1. Next, we're going to create some predefined types of pizza that our users can order:
class BuildYourOwn(init: Pizza.() -> Unit = {}) :                    Pizza("Build Your Own Pizza") {    init ...

Get Mastering Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.