Question
Which SOLID principle emphasizes that a class should
have only one reason to change?Solution
The Single Responsibility Principle (SRP) in SOLID design principles states that a class should have only one reason to change, meaning it should encapsulate only one responsibility. This principle promotes cohesion and ensures that each class handles a single task or functionality. For instance, in an inventory management system, a Product class should handle product-related data only, while a separate Inventory class manages stock levels. Adhering to SRP reduces complexity, makes code easier to understand, and simplifies debugging and testing. By isolating responsibilities, developers can introduce changes without affecting unrelated parts of the system. Why Other Options Are Incorrect :
- Open/Closed Principle : Focuses on extending classes without modifying existing code, not on single responsibility.
- Liskov Substitution Principle : Ensures that derived classes can be substituted for their base classes without breaking functionality.
- Dependency Inversion Principle : Encourages dependency on abstractions rather than concrete implementations, unrelated to single responsibilities.
- Interface Segregation Principle : Suggests splitting large interfaces into smaller, specific ones, focusing on interface design, not class responsibilities.
The Legend of Lakshmi Prasad by Twinkle Khanna is a compilation of 4 distinct short stories, one of them being inspired by real life.
Who is the author of the book ‘Courts of India: Past to Present’?
The beneficiaries under the Integrated Child Development Services (ICDS) Scheme are children in the age group of:
Where is Duncan passage located?Â
What was the code name given by Indian Air Force for February 2019 surgical Strike on Balakot?Â
Which of the following Indian musicians was referred to as ‘Ghazal King’?
In the following question, select the missing number from the given alternatives.
45, 15, 60, 75, 135, ?
In June 2020, Amit Panghal and Vikas Krishan were nominated for ______ by the Boxing Federation of India.
Where will the first IIT campus outside India be established to expand the reach of the Indian Institutes of Technology (IITs)?
Consider the following statements about e-Shakti initiate of the Government of India:
1. e-Shakti is a pilot project of National Bank for Agricul...