An iOS Engineer’s Perspective on SOLID Principles

How SOLID applies to the iOS and Swift worlds

Kelvin Tan
Swiftly Engineered iOS

--

A color-blocked background with the word SOLID in the foreground.
Image credit: Author

SOLID is made up of five design principles meant to make code more understandable, flexible, and maintainable. The principle first appeared in a 2000 paper called “Design Principles and Design Patterns” by Robert Martin, but the acronym SOLID was introduced by Michael Feathers, according to Wikipedia.

I hope when you land yourself on this article, you have the desire to actually want to become a better engineer or write better code. When engineers write code, we should think about the scalability of the code and if the code is readable by different engineers. If we don’t, we’ve got a big problem — which we need to address by following the SOLID principles.

Principle #1: Single Responsibility

Each class should have only one responsibility

By looking at the line of code, we could probably somehow measure how many responsibilities actually lie in the class. With that, I’m taking different examples from different sources to better help us measure how many lines of code we should have.

  • According to Code Complete, a study from 1996 found that classes with more routines had more defects.

--

--

Kelvin Tan
Swiftly Engineered iOS

Father, husband, software engineer. Building software and building a family, one line of code and one moment at a time. 🚀💻💙 http://ko-fi.com/kelvintanzy