100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Swift

Protocol-Oriented Programming in Swift

Explore Swift's protocol-oriented design philosophy, which favors composing small protocols over deep class inheritance.

Protocols & GenericsAdvanced10 min readJul 8, 2026
Analogies

Introduction

Protocol-oriented programming (POP) is a design philosophy in Swift, famously promoted at WWDC 2015 in the talk "Protocol-Oriented Programming in Swift," that favors composing behavior from small, focused protocols rather than building deep class inheritance hierarchies. A key enabler of POP is protocol extensions, which let you provide a default implementation for a protocol's methods so that every conforming type gets that behavior for free, unless it chooses to override it.

🏏

Cricket analogy: Rather than forcing every player through one rigid 'Cricketer' class hierarchy, POP is like giving small skill badges — Batter, Bowler, Fielder — that any player can adopt, echoing how WWDC 2015 promoted composing behavior from focused capabilities instead of deep inheritance.

Syntax

swift
protocol Greetable {
    var name: String { get }
    func greet()
}

extension Greetable {
    func greet() {
        print("Hello, \(name)!")
    }
}

Explanation

Here Greetable declares two requirements, name and greet(). The extension on Greetable supplies a default implementation of greet() that uses the conforming type's name property. Any type that adopts Greetable automatically gets this default greet() behavior without writing any code, but it can still override greet() with its own implementation if it needs different behavior. This pattern lets many unrelated structs, classes, and enums share behavior through composition of small protocols, instead of being forced into a single rigid class hierarchy.

🏏

Cricket analogy: Greetable is like a 'Fielder' certification requiring a position name and a default catching technique; any player adopting it gets the standard technique for free, like inheriting a default slip-catching style, but a specialist can still override it with their own diving style.

Example

swift
protocol Greetable {
    var name: String { get }
    func greet()
}

extension Greetable {
    func greet() {
        print("Hello, \(name)!")
    }
}

struct Visitor: Greetable {
    var name: String
}

let guest = Visitor(name: "Ava")
guest.greet()

Output

swift
Hello, Ava!

Key Takeaways

  • Protocol-oriented programming favors composing small protocols over deep class inheritance.
  • Protocol extensions can provide default implementations that all conforming types receive automatically.
  • Conforming types can override a default implementation with their own custom behavior.
  • POP works across structs, classes, and enums, not just classes as with traditional inheritance.
  • This approach was popularized by Apple's WWDC 2015 talk on Protocol-Oriented Programming in Swift.

Practice what you learned

Was this page helpful?

Topics covered

#Swift#SwiftProgrammingStudyNotes#Programming#ProtocolOrientedProgrammingInSwift#Protocol#Oriented#Syntax#Explanation#StudyNotes#SkillVeris