O'Reilly logo

Beginning Swift Programming by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9 Inheritance

WHAT YOU WILL LEARN IN THIS CHAPTER:                  

  • What inheritance is
  • How to define and instantiate a base class
  • How to create an abstract class
  • How to inherit a base class
  • How to override methods
  • How to override initializers
  • How to overload initializers
  • How to create abstract methods
  • How to overload methods
  • How to prevent subclassing
  • The different types of initializers
  • How to perform initializer chaining
  • How to call initializers in subclasses
  • Using extensions in Swift
  • Using access controls in Swift

In the previous chapter, you learned how classes are defined and how to add methods and properties to a class. In this chapter, you continue to explore object-oriented programming (OOP) by looking at another important topic—inheritance. In addition, you will also learn about access controls and how Swift’s interpretation of access control is different from conventional programming languages.

UNDERSTANDING INHERITANCE

Class inheritance is one of the cornerstones of OOP. It basically means that a class can inherit the properties and methods from another class. Class inheritance enables a high degree of code reuse, allowing the same implementation to be adapted for another use. Swift fully supports the capability of class inheritance.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required