
Single Responsibility Principle (SRP): Theory and Implementation in Swift
What is Single Responsibility Principle SRP, or Single Responsibility Principle, states that a class should have only one reason to change. In other words, the class should represent one cohesive responsibility. If a class changes for multiple unrelated reasons, it is likely handling more than one responsibility. When unrelated responsibilities are mixed in one class, the class becomes less cohesive. A change for one concern can affect code that serves another concern, which makes the class harder to test, maintain, and modify safely. Mental Model The mental model of SRP is to think about how many reasons a class has to change . Another way to think about it is to ask: How many kinds of changes could be requested for this class? How many sources of change affect this class? In Uncle Bob ’s explanation here Uncle Bob SOLID principles , these sources of change are often described in terms of different actors . An actor represents a person or group that interacts with the system and may r
Continue reading on Dev.to
Opens in a new tab

