software master at the intersection of technology, science and art



single responsibility principle

Single Responsibilty Prinicple (SRP) is that

A module should be responsible to one, and only one, actor.

The principle has been applied to functions but it actually applies to modules which may be a combination of functions and classes. The principle resolves the issue when there is a module which may be used by two different actors and one actor requires a change to a module which does not fit the use-case of the other actor. This can percolate a harmful scenario. Historically, the principle was stated as

A module should have one, and only one, reason to change.

A module is defined as a cohesive set of functions and data. This principle is also supplied to functions - in this case the function should perform a single purpose so it the code can clearly be read and understood.