Single Responsibility Principle (SRP)
Single Responsibility Principle (SRP)

In this course, we explore the SOLID principles one by one and look at how they work.

Learning Objectives

  • Understand what SOLID principles are

Intended Audience

  • Beginner Java developers
  • Anyone with a desire to learn about SOLID principles


  • Basic Java knowledge

Hello, dear friends. In this video, we will examine single responsibility, as you know the S letter in  SOLID. So, let's begin. According to Wikipedia, the single responsibility principle states that every class should have responsibility over a single part of the functionality provided by the software. And that responsibility should be entirely encapsulated by the class. Basically, a class should only have these classes methods because every class has a different purpose. If you don't follow the single responsibility principle as seen in the image, your code will be like a pocket knife, making it incredibly challenging to locate any methods or functions in the structure. If on the other hand you code with SRP, your code will look like this. As you can see, we have a tool for each mission. In real life a pocket knife maybe more useful. However, this will be a problem in programming.

Large projects may contain more than 1000 pages, so it will be difficult to find any method in this project. As a result, we must employ the single responsibility principle, SRP. For example, in an employee project we must complete all missions in a class. As shown in the image, we have an employee class in three methods. This code does not correspond to SRP because as you can see, we have a method called salary calculation. If you want to code with SRP, you have to design pages like this. As you see now, we have two classes, we can add and update employee  as employee, and we have another class called salary in which we must define the CalculateSalary method. I hope you now have a better understanding of SRP. In the next video, we will look at the O letter in  SOLID as it relates to the open-closed principle. So, I'll see you in the following video, my friends.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.