Member-only story
Single Responsibility Principle in Python
With easy to follow explanations for the beginners
Getting software to work and making software clean are two very different activities — Robert C.Martin (Clean Code)
While coding, you can easily get carried away by the tasks at hand, and only focus on getting your code to work. As a result, you lost track of lines you are adding to your code, and end up with bulky, not organised, yet working functions.
The single responsibility principle is a software design guideline which states that every module, class or function in your code should have only one responsibility and only one reason to change.
This principle is all about organising the complexity of your code, gathering together the things that change for the same reasons so that you know where to look to modify things without considering all the complexity involved.
Read on to learn more about the single responsibility principle, why and how it is implemented in Python.
Benefits of applying the Single Responsibility Principle
If you follow the single responsibility principle, you will end up with a large number of small functions, or classes instead of large ones.