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.
Whose autobiography is titled 'Waiting for a Visa'?
Lal Kangaroo is the national animal of which of the following nations?
What is the currency of Greece?
According to the United Nations Convention on the Law of the Sea (UNCLOS), up to how many nautical miles can a country's baseline extend to define its t...
Which of the following places is also known as ‘Cape Comorin’?
Which one of the following (Folk Dance Area) is not matched correctly?
Under which Act was the rule of British Crown established over India?
Raja Ram Mohan Roy founded a reform association known as Brahmo Sabha which was later known as ______.
Bharatnatyam is related to which of the following?
Till November 2021, how many All India Financial Institutions does our country have?