iOS Best Practices. Part 4: S.O.L.I.D
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
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.
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.
L — Liskov Substitution Principle (LSP)
Derived classes must be substitutable for their base classes.
I — Interface Segregation Principle (ISP)
Make simple abstractions that clients need.
D — Dependency Inversion Principle
Depend on abstractions not on specific classes/structures.
Abstractions Everywhere! Remember it!
This was a small guide about S.O.L.I.D practice in swift code.