From the course: iOS Development: Architecture

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Interface segregation

Interface segregation

From the course: iOS Development: Architecture

Start my 1-month free trial

Interface segregation

- [Instructor] The interface segregation principle deals with the problem of fat interfaces. A fat or polluted interface means that it exposes too many properties and methods. This issue can affect our types and protocols. Our interfaces are narrow at the beginning, but as we keep adding new functionality and expose new public methods, the interfaces become bloated. As a result, the clients will depend on methods they don't need. In the case of protocols, we force adopting types to implement a bunch of methods and computed properties that are irrelevant for most types. The interface segregation principle says that clients shouldn't depend upon interfaces they don't use. So let's take a look at the image protocol. Types that adopt this protocol need to implement all the methods and computed properties. Now, what if we don't need the Base64 encoding feature for retrieving the image's jpeg data? The solution is to expose the narrowest interface. Swift offers elegant ways to solve this…

Contents