3 ms·
Imagine a protocol for a download: Required 1. Download finishes 2. Download fails Optional 3. Download progress (for updating a progress bar) This seems leg
by mapmap 8y ago
Imagine a protocol for a download:
Required
1. Download finishes
2. Download fails
Optional
3. Download progress (for updating a progress bar)
This seems legit to me. Would one really want the added overhead of having to implement 3 as a separate protocol?
- Razengan 8y agoYou'd present that as `ProgressReporting` or something, because other tasks besides a download would want to report their progress too, and indeed, the Foundation framework already has such a protocol [0]! In your first comment you seem to value the ability to "quickly digest key object interfaces and concepts" but you balk at the added clarity afforded by separating different behaviors into distinct protocols? If by "overhead" you mean a cost to performance, worrying about it at that level falls under premature optimization, until you're certain that the extra protocol noticeably harms performance. If you really insist on having a single protocol, then make `progress` an optional computed property. [0] https://developer.apple.com/documentation/foundation/progressreporting https://developer.apple.com/documentation/foundation/progres... [1] https://developer.apple.com/documentation/foundation/progress https://developer.apple.com/documentation/foundation/progres...