iOS Best Practices. Part 4: S.O.L.I.D

Maksim Vialykh
1 min readJan 5, 2018

--

As a continuation of Part 3: Architecture

Let’s talk about S.O.L.I.D. principles and and how they can be applied in Swift.

S — The Single Responsibility Principle

Too strong class

strong presenter

This class works with logic, makes Network requests and does navigation work.
So, let’s simplify it and rework it using The Single Responsibility Principle.

Single Responsibility

O — Open-Closed Pronciple (OCP)

It’s a principle for object oriented design first described by Bertrand Meyer that says that “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification”.

First — create protocol abstractions,
Then — create final implementation,
do — extensions,
Not do — changes.

Open-Closed

L — Liskov Substitution Principle (LSP)

Derived classes must be substitutable for their base classes.

liskov substitution

I — Interface Segregation Principle (ISP)

Make simple abstractions that clients need.

interface segregation

D — Dependency Inversion Principle

Depend on abstractions not on specific classes/structures.

dependency inversion

Abstractions Everywhere! Remember it!

This was a small guide about S.O.L.I.D practice in swift code.

Part 4: Project Setup

--

--