Single Responsibility


SOLID Principles
What is SOLID?
15m 18s

The course is part of this learning path

Single Responsibility

This course looks at the five SOLID principles starting with a little bit of their history before moving on to cover each principle in more detail.

Learning Objectives

  • Learn about the five SOLID principles:
    • Single Responsibility
    • OpenClosed
    • Liskov Principle
    • Interface Segregation
    • Dependency Inversion

Intended Audience

This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE.


Basic knowledge of Java programming.


Hello dear friends. In this video, we'll 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 this classes method 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 to a pocket knife, making it incredibly challenging to locate any methods or functions in this 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 may be more useful. However, this will be a problem in programming. Large projects may contain more than 1,000 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 and 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 can see, now we have two classes. We can add and update employees in 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 following video, we will look at the O letter in SOLID, as it relates to the OpenClosed principle. See you in the following video.


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.

Covered Topics