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.
Two numbers differ by 5 and their sum is 55. Find them.
In a school a total of 2,430 chocolates were distributed among all the students in the school. The chocolates were distributed in such a way that numbe...
If x and y are two digits of the number 85254xy such that this number is divisible by 90. Find the minimum value of x + y?
- Find the median of the following observations:
101, 104, 99, 97, 102, 106, 105 If three positive numbers are in the ratio 4:6:5 and the sum of their squares equals 1925, determine the smallest of these three ...
A number is increased by 20% then reduced by 20%. If final value is 144, find original number.
Find the remainder when the number (289n + 95) is divided by 17.
Find the value of 6 + 66 + 666 + 6666 +hellip;hellip;hellip;hellip;.. + n terms.
1. `(2)/(3) ((10 xx (10^(n)- 1))/9 - n)`
2.
The Indian cricket team scored 188 runs in their 20-over match against Australia. By the end of the 13th over, Australia has scored 107 runs. What is th...