Recall & Review
beginner
What is protocol-oriented architecture in Swift?
It is a design approach that uses protocols to define blueprints of methods and properties. Types then conform to these protocols to share behavior, promoting code reuse and flexibility.
Click to reveal answer
intermediate
How does protocol-oriented architecture differ from class inheritance?Instead of inheriting from a base class, types conform to protocols. This avoids tight coupling and allows multiple behaviors to be combined, unlike single inheritance.
Click to reveal answer
intermediate
What is a protocol extension in Swift?
A protocol extension adds default method or property implementations to a protocol, so conforming types get this behavior automatically unless they override it.
Click to reveal answer
intermediate
Why is protocol-oriented architecture beneficial for testing?
Protocols allow you to create mock or stub types easily by conforming to the protocol, enabling isolated and flexible unit testing.
Click to reveal answer
beginner
Give an example of a simple protocol in Swift.
Example:
protocol Drivable {
func drive()
}
Any type that conforms to Drivable must implement the drive() method.Click to reveal answer
What keyword defines a protocol in Swift?
✗ Incorrect
Swift uses the keyword
protocol to define protocols.Which of these is a benefit of protocol-oriented architecture?
✗ Incorrect
Protocols let types adopt multiple behaviors, similar to multiple inheritance.
What feature lets you provide default implementations in protocols?
✗ Incorrect
Protocol extensions allow default method implementations.
Which type can conform to a protocol in Swift?
✗ Incorrect
Classes, structs, and enums can all conform to protocols.
Why is protocol-oriented architecture good for testing?
✗ Incorrect
Protocols let you create mock implementations for testing.
Explain protocol-oriented architecture and how it improves code flexibility in Swift.
Think about how protocols define behavior and how types adopt them.
You got /4 concepts.
Describe how protocol extensions work and why they are useful.
Consider how you can add methods to protocols themselves.
You got /4 concepts.