Question
Which SOLID principle emphasizes that a class should
have only one reason to change, promoting single responsibility?Solution
The Single Responsibility Principle (SRP) is a part of the SOLID principles of object-oriented design. It states that a class should have only one reason to change, meaning that a class should only have one responsibility or job. By following SRP, classes are kept small and focused, which makes them easier to understand, maintain, and extend. A violation of this principle often leads to tightly coupled code and difficulty in maintaining or extending the system as it evolves. SRP encourages better separation of concerns in a software system. For example, in an application, a class responsible for user authentication should not also manage user notifications, as these are separate responsibilities that may change for different reasons. Why Other Options Are Wrong: A) Open/Closed Principle: This principle states that software entities should be open for extension but closed for modification. It is focused on enhancing existing code without altering it, not on class responsibilities. B) Liskov Substitution Principle: This principle states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program. It does not address responsibility. C) Dependency Inversion Principle: This principle suggests that high-level modules should not depend on low-level modules, but rather on abstractions. It focuses on reducing coupling between classes, not responsibility. E) Interface Segregation Principle: This principle suggests that clients should not be forced to depend on interfaces they do not use. It deals with designing better interfaces, not with a class’s responsibility.
Mr. Vivek divides Rs. 1703 such that 4 times the 1st share, thrice the 2nd share and twice the third share amount to the same. Then the value of the 2nd...
A wire is bent to form a square whose sides are of 44 cm. If the same wire is bent to form a circle, then find the area (in cm2) of the circl...
A cuboid has length 8 cm, breadth 6 cm and height 4 cm. Find the length of its space diagonal and its total surface area.
The length and breadth of a rectangular field are 45 m and 28 m respectively. What is its area?
If the diameter of a solid hemisphere is 12.6cm, then its volume is taken π =22/7
A solid metallic cylinder of radius 5 cm and height 8 cm is melted and recast into 10 identical solid cones, each having radius 2 cm. What is the height...
On a rectangular wall of length 35 metres and height 30 metres, there is a window in the shape of triangle surmounted on a square. If the base of triang...
Find the total surface area of a right circular cone whose height is 4 cm and volume is 36 cm³. (Take π = 3)
The value of tan2 θ + cot2 θ − sec2 θ cosec2 θ is:
Each side of square ‘A’ is 8 cm less than that of square ‘B’. The perimeter of a rectangle is 6 times the difference of the perimeters of the tw...