This chapter has us creating three separate extensions on the Exercise protocol:
extension Exercise {
var caloriesBurnedPerMinute: Double {
return caloriesBurned / minutes
}
}
extension Exercise {
var description: String {
return "Exercise(\(name), burned \(caloriesBurned) calories
in \(minutes) minutes)"
}
}
extension Exercise {
var title: String {
return "\(name) - \(minutes) minutes"
}
}
This seems strange to me. Why would you create three separate extensions instead of just one? I tried combining the behavior of these three extensions into one, as follows, and it worked just fine:
extension Exercise {
var description: String {
return "Exercise(\(name), burned \(caloriesBurned) calories in \(minutes) minutes)"
}
var caloriesBurnedPerMinute: Double {
return caloriesBurned / minutes
}
var title: String {
return "\(name) - \(minutes) minutes"
}
}
So what is the point of making three extensions in this situation rather than just one? It seems much simpler and concise to use just a single extension.