All about the Separation of Concerns principle
I have mentioned the SoC principle in the book several times. In fact, I mentioned this principle many times in my previous books and articles as well. In a way, the SoC principle sits at the heart of many design patterns and architectural decisions, and for a pretty good reason. Before we dive into understanding why, let’s try to understand what SoC means.
Defining the Separation of Concerns principle
We’ll begin with defining what SoC is. SoC refers to organizing code to separate different functionalities into different objects and owners. It means that a class or a module must have one and only one responsibility.
Look at the following example:
func processUserData(userData: [String: Any]) { // Responsibility 1: Validate the data guard let name = userData["name"] as? String, ...