Skip to content

Latest commit

 

History

History
29 lines (18 loc) · 1.45 KB

File metadata and controls

29 lines (18 loc) · 1.45 KB

Single responsability principle

The single-responsibility principle (SRP) is a computer-programming principle that states that every module, class or function in a computer program should have responsibility over a single part of that program's functionality, and it should encapsulate that part. All of that module, class or function's services should be narrowly aligned with that responsibility.

Wrong interpretation of the principle

Most developers interpret to mean that a class should perform only one task. But it's not only classes, functions you implement in code during development should also perform only one task. So one should interpret it as meaning that an implementation should perform only one task.

One class can perform multiple tasks, there is no question of that, but it's not going to provide quality / better output.

So to get good quality/better output of work, one method should do one task at time.

🧠 See the code and you'll learn:

  • What the single responsibility principle is
  • Why the single responsibility principle is important
  • How to use the single responsibility principle
  • How to spot violations of the single responsibility principle

Advantages

  • Clean: clean and standard code
  • Maintainable: Manageable and easy for maintenance
  • Scalable and redable: Easy to refactor or change and readeble code

Disadvantages

  • To many small modules/classes
  • Take more time for development and increases project cost