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.
Which bank has partnered with the Institute of Rural Management Anand (IRMA)to enhance and expedite the advancement of financial inclusion (FI) and fi...
What strategic move has been approved by the Union Cabinet chaired by the Prime Minister, Narendra Modi, regarding Surat Airport?
What is the purpose of the agreement signed between Google Pay and NPCI International Payments?
Amazon India has signed an MoU with which state for turning rural women into entrepreneurs?
Who was the first Indian male wrestler to win an MMA fight?
What was the theme for “National Maritime day” this year?
Where is the headquarter of Transparency international?
Which e-commerce marketplace announced the signing of a MoU with Varanasi to enable national market access for artisans, weavers, and people with disabi...
India and Algeria signed a Memorandum of Understanding (MoU) to boost cooperation in which area?
Who has been chosen as the Business Standard Banker of the Year 2022?