From the course: Swift 5: Protocol-Oriented Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Why protocols?

Why protocols?

From the course: Swift 5: Protocol-Oriented Programming

Start my 1-month free trial

Why protocols?

- Why are protocols and protocol inheritance preferred over base classes and subclassing? Because, as we'll see, protocols serve as better abstractions than classes. Modeling a system using classes implies inheritance. What's wrong with inheritance, you might ask? It's been around for a while, and we've been using it to build various software products. That's right, inheritance works great until we hit some of its restrictions. Let's take a look at both the benefits and the drawbacks of this fundamental object-orientation concept. The superclass provides the core functionality. It includes all the logic required to satisfy the requirements for that given type. If we need more specific behavior, we can add subclasses. A subclass can use the default behavior defined in the superclass, completely override or decorate the behavior from the base class. Inheritance gives us a lot of flexibility and freedom. However, it has some…

Contents