The SOLID Principles Applied to Swift

Let us apply Uncle Bob’s acronym to Swift!

Steven Curtis
4 min readNov 9, 2020
Photo by Berenice Melis @brrknees on Unsplash

I’ve already touched upon the SOLID pinciples, like in my articles about dependency injection, yet I think there is a need for the principles to be outlined in an article that can be used for quick-reference (with examples). Read on for just such an article

Why SOLID?

You might well have heard of the SOLID Principles, which are five of Robert Cecil Matin’s principles.

They have been in use for coding in the Object-Oriented paradigm for twenty or so years. The idea of these principles is to improve how robost code is against bugs, encourage code reuse and make code more flexible (so changes can easily be made in code).

The 5 principles here are covered with Swift examples. I’ve even got a link to some code snippets in my repo — read on for the details!

The S — The Single Responsibility Principle (SRP)

There should never be more than one reason for a class to change. If a class has multiple reasons to change this can increase complexity and make it tricky to track down bugs. We don’t want that!

In respect to iOS development there has always been a danger that too many reponsibilities are placed…

--

--

Responses (2)