Now, let's add the ability to add a pizza to our order, as well as configure it:
- 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")
- 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.
- 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 ...