Michael Long
Oct 28, 2023

--

Enjoyed the article, but I'm not sure I'm convinced. Your service demonstrates well with a simple variable for the type (Entity), but most "service" implementations of this nature have more complex behaviors like making API requests.

One could make a generic implementation of an API fetcher, of course, but one then typically runs into an implementation that needs additional parameters or other requirements and you're back to needing a protocol.

The protocol witness basically depends on a switch statement to emulate polymorphic behaviors.

And that's something that's usually considered to be a code smell. Better in my opinion to wrap it into a protocol and get the polymorphic behavior for free as opposed to writing additional code that reimplements what the compiler already does under the hood.

But thanks for the thought-provoking aritlce.

(Which just came up in my feed years later...)

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet