Swift as an object-oriented programming language
Swift fully supports developing applications using object-oriented principles. When it was first released, it was primarily viewed as an object-oriented language, much like Java and C#. In this section, we will design the vehicle types using an object-oriented approch and examine the advantages and disadvantages of this design.
Before looking at the code, let's create a basic diagram to illustrate the vehicle class hierarchy in our object-oriented design. In this design, we use a class hierarchy to group related classes. With Swift being a single inheritance language, each class can inherit from only one superclass. The root class in the hierarchy is the only class without a superclass.
I typically begin with a simple diagram that outlines the classes without much detail, this allows me to visualize the class hierarchy. The following diagram shows the class hierarchy for our object-oriented design:
This diagram shows that we have...