From the course: iOS Development: Architecture

Unlock the full course today

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

Single responsibility

Single responsibility

From the course: iOS Development: Architecture

Start my 1-month free trial

Single responsibility

- [Narrator] The single responsibility principle tells us that each type should have one well-defined responsibility. Let's say that our software needs to operate with multiple currencies. We could create a class that fetches the exchange rates, stores them in the local persistence, and performs the currency conversions. However, this would assign too many responsibilities to our class, networking, persistence, and converting between currency pairs. If we follow the single responsibility principle, we'd need at least three different classes. As we see it on the right side, we've got one that performs the conversions, one for the networking functionality, and one for managing the local persistence. This separation of concerns makes our life easier, especially if we need to fix bugs or make changes to the software. Instead of modifying a big monolithic component, we can isolate the changes to smaller units. Testing also becomes more straightforward as we can mock certain classes if we…

Contents