10.2. Creating a single protocol from multiple protocols
Let's assume we need to write a protocol for Teaching Assistants (TA). The TAs are paid, receive TA training, and are rated by the professors. Let's assume that we have protocols to pay people, conduct TA training, and rating TAs:
//protocol for payment...
protocol Payment{
func biweeklyPayment() -> Double
}
//protocol for TA training...
protocol TATraining{
func completeTraining()
}
//protocol for TA rating...
protocol RatedByProfessor{
func rate() -> Int
}Now, we can consolidate all the protocols into one for the TAs like:
// Some code//consolidating to a single protocol...
protocol TeachingAssistant: Payment, TATraining, RatedByProfessor{
//properties and methods for TeachingAssistant protocol...
}Last updated
Was this helpful?