-
Book Overview & Buying
-
Table Of Contents
Mastering Swift 6 - Seventh Edition
By :
Two of the issues we encountered with the object-oriented design are directly related to Swift being a single-inheritance language meaning that a class can have only one superclass.
In a single-inheritance language like Swift, object-oriented design can result in bloated superclasses because we may need to include functionality that only a few subclasses require. This leads to the second issue of subclasses inheriting unnecessary functionality that they don’t use
In our design, we had to include functionality for all three terrain types because the vehicle types might need to operate any of the terrains. This extra functionality could lead to errors if we are not careful. It's easy to accidentally create a class similar to this:
class Infantry: Vehicle {
override init() {
super.init()
vehicleTypes = [.land]
vehicleAttackTypes = [.land]
vehicleMovementTypes = [.sea]
landAttackRange...