Question
Which SOLID principle ensures that a class has only one
reason to change?Solution
The Single Responsibility Principle (SRP) states that a class should have only one reason to change, meaning it should have only one responsibility or function. This principle promotes cohesion by ensuring each class handles a specific part of the software functionality. For instance, a Customer class should handle customer data, while an Invoice class manages invoice generation. Adhering to SRP simplifies debugging, enhances maintainability, and prevents interdependent changes from cascading through the codebase. Why Other Options Are Incorrect :
- Open/Closed Principle : This emphasizes that classes should be open for extension but closed for modification, unrelated to SRP.
- Liskov Substitution Principle : This ensures that derived classes can replace base classes without altering program correctness.
- Dependency Inversion Principle : This recommends high-level modules should not depend on low-level modules but rather on abstractions.
- Interface Segregation Principle : This advises against forcing a class to implement interfaces it does not use, unrelated to SRP.
In which of the Himalayan valleys, Shipki-La pass is located?
What position did India hold in the Global Intellectual Property Index 2024 among the 55 countries that were assessed?
How much funding has been allocated for the RAMP Scheme over a period of five years?
Vir Das won the 2023 International Emmy Award for Best Comedy Series for which of the following shows?
In which year did the Bengal famine occur?
What is the Golden Quadrilateral in India?
In its latest Fiscal Monitor report, the IMF showed that India’s combined debt-to-GDP ratio (Centre plus states) will rise to _____ in FY27.
Which is the state bird of Haryana?
Who was the founder of Prarthana Samaj?
The Equator does not pass through which one of the following countries?