📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      Which SOLID principle emphasizes that a class should

      have only one reason to change, promoting single responsibility?
      A Open/Closed Principle Correct Answer Incorrect Answer
      B Liskov Substitution Principle Correct Answer Incorrect Answer
      C Dependency Inversion Principle Correct Answer Incorrect Answer
      D Single Responsibility Principle Correct Answer Incorrect Answer
      E Interface Segregation Principle Correct Answer Incorrect Answer

      Solution

      The Single Responsibility Principle (SRP) is a part of the SOLID principles of object-oriented design. It states that a class should have only one reason to change, meaning that a class should only have one responsibility or job. By following SRP, classes are kept small and focused, which makes them easier to understand, maintain, and extend. A violation of this principle often leads to tightly coupled code and difficulty in maintaining or extending the system as it evolves. SRP encourages better separation of concerns in a software system. For example, in an application, a class responsible for user authentication should not also manage user notifications, as these are separate responsibilities that may change for different reasons. Why Other Options Are Wrong: A) Open/Closed Principle: This principle states that software entities should be open for extension but closed for modification. It is focused on enhancing existing code without altering it, not on class responsibilities. B) Liskov Substitution Principle: This principle states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program. It does not address responsibility. C) Dependency Inversion Principle: This principle suggests that high-level modules should not depend on low-level modules, but rather on abstractions. It focuses on reducing coupling between classes, not responsibility. E) Interface Segregation Principle: This principle suggests that clients should not be forced to depend on interfaces they do not use. It deals with designing better interfaces, not with a class’s responsibility.

      Practice Next

      Relevant for Exams:

      ask-question