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.
Ragini borrowed βΉ21,600 at a simple interest rate of 18% per annum, while Misthi borrowed βΉ51,200 at an annual compound interest rate of 12.5%. Curr...
A certain amount becomes Rs. 7,680 in 6 years and Rs. 9,120 in 9 years on simple interest. Determine the rate of interest per year.
Rs. 5000 is invested in scheme βAβ for 2 years and Rs. 8000 is invested in scheme βBβ for 2 years. Scheme βAβ offers simple interest of 16% ...
The difference between the compound interest, compounded annually and simple interest on Rs. βPβ at the rate of 25% p.a. for 2 years, is Rs. 150. If...
A invested Rs. βxβ in a scheme offering compound interest of 40% p.a. compounded annually. If at the end of 2 years, interest received by A was Rs. ...
A farmer wants to divide Rs 1,22,000 between his sons , who are 18 and 20 years old respectively, in such a way that the sum divided at the rate of 20% ...
A sum of Rs. 3000 is invested at simple interest for 2 years. If the rate interest for first year is 10% p.a. while 18% p.a. for second year, then find ...
Mr. Ghanshyam deposited certain amount in the Bank at the end of each year. How much amount did he deposit at the end of each year at the rate of 15% si...
A man deposited Rs. βx + 700β at 12% per annum simple interest and earned Rs. 624 as interest after 2 years. Find the interest earned by him if he d...
Compound interest on a certain sum of money for 2 years is Rs.3600 while the simple interest on the same sum for the same time period is Rs.3200. Find t...