public protocol EveryoneCanHandleThis {
func handleMeItsFree()
}
private struct SecretHandler: EveryoneCanHandleThis {
func handleMeItsFree() {
// This is free by today
}
}
func giveMeAHandler() -> some EveryoneCanHandleThis {
return SecretHandler()
}
By returning an opaque return type we can hide the implementation and later ...
private struct EvolvedSecretHandler: EveryoneCanHandleThis {
func handleMeItsFree() {
// Now we are charging users in a secret way but they still thinks that it's free
}
}
func giveMeAHandler() -> some EveryoneCanHandleThis {
return EvolvedSecretHandler()
}
change the implementation and callers doesn't need to change a line.
By returning an opaque return type we can hide the implementation and later ...
change the implementation and callers doesn't need to change a line.