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.
Cnsider the following statements regarding Swachh Vayu Sarvekshan-2023-
I.According to the Swachh Vayu Sarvekshan-2023 (or Clean Air Survey), con...
Which community’s cultural heritage is celebrated at the newly inaugurated Banjara Virasat Museum in Maharashtra?
The Reserve Bank of India (RBI) has increased the threshold limit of non-callable deposits for providing more flexibility to depositors. The threshold l...
By what year does NASA plan to build a 100-kilowatt nuclear reactor on the Moon?
What initiative by the Reserve Bank of India (RBI) aims to enhance digital wallet interoperability in 2024?Â
Fitch Ratings has slashed its 2022-23 current account deficit projection for India to 2.3% of GDP from 3.3% in December 2022, and expects the deficit to...
What is the primary goal of the partnership between the Ministry of Panchayati Raj and UNICEF India?
What is TROPEX-23 recently conducted by The Indian Navy?
I. A cultural festival held by the Indian Navy
II. A training program for Navy pe...
Who became the new President of Brazil?
______ and Genpact have launched Be.Seen — a program to help scale businesses owned by minority and under-represented groups in India with an aim to...