Start learning 50% faster. Sign in now
The Single Responsibility Principle (SRP) is one of the core SOLID principles in object-oriented programming. It states that a class should have only one reason to change, meaning it should only be responsible for one aspect of the software’s functionality. This principle promotes high cohesion within a class and low coupling between classes, making the system more modular and easier to maintain. By adhering to SRP, developers can avoid the pitfalls of "God Classes," which handle multiple responsibilities and can lead to code that is difficult to debug, test, or extend. For example, a Report class that both formats and sends reports violates SRP, as changes to formatting or delivery methods would require modifying the same class. By separating these responsibilities into dedicated classes, such as ReportFormatter and ReportSender , the design becomes cleaner and easier to adapt to changes. Following SRP results in smaller, well-defined classes that are easier to understand, test, and maintain. It reduces the risk of introducing bugs when making changes, as a single modification is unlikely to impact unrelated parts of the application. Explanation of Incorrect Options: A) Open/Closed Principle : The Open/Closed Principle states that a class should be open for extension but closed for modification. While it ensures flexibility and stability, it focuses on adding new functionality without altering existing code. It does not emphasize the segregation of responsibilities within a class, making it incorrect in this context. B) Liskov Substitution Principle : The Liskov Substitution Principle ensures that derived classes can be substituted for their base classes without altering the correctness of the program. This principle addresses the behavior of subclasses but does not relate to a class having a single responsibility. C) Interface Segregation Principle : This principle advocates for creating small, specific interfaces instead of large, general ones. It ensures that classes implementing an interface are not burdened with methods they do not use. While important for interface design, it does not directly address the issue of a single reason for a class to change. E) Dependency Inversion Principle : The Dependency Inversion Principle emphasizes depending on abstractions rather than concrete implementations. It promotes flexibility and reduces tight coupling between high-level and low-level modules but does not ensure a single responsibility within a class.
Which Indian district was highlighted in ISRO's Landslide Atlas of India for its high risk related to landslides?
59-minute loan approval scheme for micro, small and medium enterprises (MSMEs) Is of____?
Bank of Baroda has collaborated to offer co-branded RuPay Platinum Debit Card to beneficiaries of the state government’s ‘Pudhumai Penn’ scheme.Th...
Consider the following statements in regards to generative AI.
1) It is a transformative type of artificial intelligence.
2) Accenture has...
Consider the following statements regarding Reserve Bank of India's bi-monthly Inflation Expectations Survey of Households (IESH) -
I.The Reserve...
Who among the following was appointed as new global business head of Meta in India?
What milestone did UPI achieve in October 2024, and which transaction type primarily drove this growth?
Which of the following statements is/are not true regarding the proposed changes/changes being done by the Monetary Policy Committee?
I.The Reser...
What is the primary focus of the Memorandum of Understanding (MoU) between NTPC Green Energy Limited (NGEL) and Nayara Energy?