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.
Water and steam(P)/ It used(Q)/to mechanise production(R)/ power(S).
1. It is useful to distinguish P.basic research
Q.pure science, which involves
R.and applied science
S.between two forms of science...
Given that statement 1 is the first sentence, which of the following will be the FIFTH sentence after rearrangement?
I. The recent shift (A) in e-commerce platforms has reshaped (B) consumer behavior and shopping trends, leading to a significant surge (C) in the retai...
Which of the following is the fourth sentence in the paragraph?
Each question is divided into four parts a,b,c,d. In some questions they are not in the sequence so according to grammar and context re- arrangement is...
Which should be the fourth sentence after rearrangement?
Which of the following is the sixth (last) sentence of the passage?
A. master plan is being amended, to
B. enforce the sealing, especially when the
C. courts should not yield to any pressure and
D. o...
Which of the following is the fourth sentence of the passage?