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.
How is Q related to T?
A is the son of B while B and C are the sisters to one another. E is the mother of C. If D is the son of E, which of the following statements is correct...
R is the father of V, who is the brother of U. U is the daughter of T. S is the father-in-law of T. How is S related to the brother of U?
Answer the questions based on the information given below.
There are eight persons M, N, O, P, Q, R, S, and T in a family of three generations....
If F has only one child and there are four male members in the family then how is the child of F related to L?
Answer the questions based on the information given below.
There are eight members H, I, J, K, L, M, N and O in a family of three generations...
J is the father of H but H is not the son of J, who is married to Q. O is the mother-in-law of Q. How is H related to F, if F is married to O?
What is the relation of E with respect to G?
Answer the questions based on the information given below.
There are seven members D, E, F, G, H, I and J in a family, which consists of only...
Study the following information carefully and answer the given questions.
There are nine members in a family i.e. R, S, T, U, V, W, Y, Z, and A...