Book Image

Swift Cookbook

By : Cecil Costa, Cecil Costa
Book Image

Swift Cookbook

By: Cecil Costa, Cecil Costa

Overview of this book

Table of Contents (18 chapters)
Swift Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Delivering some pizzas


Imagine that you have to create a new window type, which will have a border; the first idea is borrowed from a window class, and creating a new class called BorderedWindow. You can do the same thing with scroll bars; call it ScrolledWindow. Now, if we need to create a window with scroll and border, we have to create a new class called ScrolledAndBorderedWindow, but imagine that we now need to add a double and triple bordered window, we will have lots of combinations.

To prevent this kind of problem, there is a pattern called decorator; this pattern allows us to create new object types based on a new feature.

Getting ready

Create a new project called Chapter 4 Pizzas and add the pizza image into Images.xcassets. Now, heat up the oven and let's prepare some pizzas.

How to do it...

Let's execute these steps to deliver some pizzas:

  1. First of all, let's create a base class that defines a pizza, so create a new file called Pizza.swift and create the following class:

    class BasePizza...