Protocol Composition with &
Combining multiple protocols into a single type requirement.
Welcome
Protocol composition lets you combine multiple protocols into a single type requirement using `&`. This is Swift's answer to multiple inheritance.
Basic Composition
```swift
protocol Named { var name: String { get } }
protocol Aged { var age: Int { get } }
func describe(_ entity: Named & Aged) {
print("\(entity.name) is \(entity.age)")
}
```
`Named & Aged` is a temporary type requirement, not a new protocol.
All lessons in this course
- Protocol Composition with &
- Conditional Conformance
- Self Requirements and Equatable Design
- Protocol-Oriented Design Principles