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.
On which date was the 87th Foundation Day of the CRPF celebrated in 2025?
Under the Pre-matric Scholarships scheme for SC & Others during FY2023-24, how much central share has been released to 7.38 lakh beneficiaries through DBT?
How much percent did World Bank cut its 2022-23 (FY23) real gross domestic product (GDP) growth forecast for India in its latest Global Economic Prospe...
What is the primary objective of the GREAT scheme, which is expected to have a positive impact on the banking industry's textile sector portfolio?
The largest city of Madhya Pradesh state area wise is?
The International Aryan Summit 2025 is part of which festival commemorating Maharshi Dayanand Saraswati Ji?
Apple, world’s most valuable company has set up manufacturing plant in India. In which state the plant is located?
What is the name of the digital library project launched in Puri to preserve Jagannath Temple records?
Which of the following statements is correct regarding the Project Swasthya Nagaram launched in Telangana for TB-Free Municipalities?
What is the conservation status of the Mainland Serow according to the IUCN Red List?