SOLID
The point
SOLID is five design principles formulated by Robert Martin (the acronym was coined by Michael Feathers). The goal is a single one: code that is easy to change and test because changes stay local and dependencies point at abstractions.
- S — Single Responsibility. A type has one reason to change (one "actor" it serves). A
UIViewControllerthat calls the network, parses JSON and formats dates changes for three different reasons — the classic Massive View Controller. - O — Open/Closed. New behavior is added with new code (a new type, a new protocol conformance), not by editing an existing
switch. - L — Liskov Substitution. A subtype can be substituted for its base type and code written against the base contract keeps working.
- I — Interface Segregation. Narrow protocols instead of "fat" ones: a client must not depend on methods it does not use. In UIKit that is
UITableViewDataSourceandUITableViewDelegate— two protocols, not one. - D — Dependency Inversion. A high-level module does not depend on a low-level one; both depend on an abstraction owned by the high level.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep