Single Responsibility

Seokchan Yun·2022년 6월 25일
0

The idea behind the SRP is that every class, module, or functions in a program should have one responsibility/purpose in a program.
As a commonly used definition, "every class should have only one reason to change".

public class Student
{
	public void registerStudent() {}
    
    public void calculate_Student_Results() {}
    
    public void send_Mail() {}
}

The class above violates the single responsibility principle.

This student class has three responsibility.

  • registering
  • calculating
  • sending email

The code work perfectly but when we use or lead, it's too complicate.

We have to separate each functionality. After, we can call the classes anywhere we want to use them in our code.

public class StudentResister {}

public class StudentResult {}

public class StudentSendEmail {}
profile
42 Paris developer

0개의 댓글