0
0
iOS Swiftmobile~5 mins

Protocol-oriented architecture in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Astruct
Binterface
Cclass
Dprotocol
Which of these is a benefit of protocol-oriented architecture?
APrevents code reuse
BForces all types to inherit from a base class
CAllows multiple inheritance of behavior
DRequires use of classes only
What feature lets you provide default implementations in protocols?
AProtocol extensions
BClass inheritance
CStructs
DEnums
Which type can conform to a protocol in Swift?
AClass
BAll of the above
CEnum
DStruct
Why is protocol-oriented architecture good for testing?
AIt allows creating mock types easily
BIt makes testing impossible
CIt requires inheritance
DIt hides all methods
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.