The Single Responsibility Principle (SRP) is one of the core SOLID principles in object-oriented programming. It states that a class should have only one reason to change, meaning it should only be responsible for one aspect of the software’s functionality. This principle promotes high cohesion within a class and low coupling between classes, making the system more modular and easier to maintain. By adhering to SRP, developers can avoid the pitfalls of "God Classes," which handle multiple responsibilities and can lead to code that is difficult to debug, test, or extend. For example, a Report class that both formats and sends reports violates SRP, as changes to formatting or delivery methods would require modifying the same class. By separating these responsibilities into dedicated classes, such as ReportFormatter and ReportSender , the design becomes cleaner and easier to adapt to changes. Following SRP results in smaller, well-defined classes that are easier to understand, test, and maintain. It reduces the risk of introducing bugs when making changes, as a single modification is unlikely to impact unrelated parts of the application. Explanation of Incorrect Options: A) Open/Closed Principle : The Open/Closed Principle states that a class should be open for extension but closed for modification. While it ensures flexibility and stability, it focuses on adding new functionality without altering existing code. It does not emphasize the segregation of responsibilities within a class, making it incorrect in this context. B) Liskov Substitution Principle : The Liskov Substitution Principle ensures that derived classes can be substituted for their base classes without altering the correctness of the program. This principle addresses the behavior of subclasses but does not relate to a class having a single responsibility. C) Interface Segregation Principle : This principle advocates for creating small, specific interfaces instead of large, general ones. It ensures that classes implementing an interface are not burdened with methods they do not use. While important for interface design, it does not directly address the issue of a single reason for a class to change. E) Dependency Inversion Principle : The Dependency Inversion Principle emphasizes depending on abstractions rather than concrete implementations. It promotes flexibility and reduces tight coupling between high-level and low-level modules but does not ensure a single responsibility within a class.
A shopkeeper allows two consecutive discounts of 20% and 25% on an article and still he makes a profit of 32% by selling it. He would make Rs.2332 less ...
A seller marked the price of an item at Rs. 5,000. The seller gave successive discounts of (b + 5)% and (b - 5)% to a customer. If the customer paid Rs....
C and D invest in a business in a ratio of 4:5. If 10% of the total profit goes to charity and D's share is Rs.900 after the donation, what is the total...
The CP of 53 stickers is equal to SP of 50 stickers. Find the gain percent.
Following the sale of apples with a 30% profit, the seller made an intriguing discovery. He observed that the marked price of an apple exceeded the comb...
There is a certain number of articles in the warehouse. Each article is given distinct codes which is either a single digit number or two consecutive si...
A shopkeeper sells an article at a Loss of 20% of the selling price. Find the actual loss percentage.
Ratio of the cost price of article ‘A’ to ‘B’ is 6:7, respectively. Article ‘A’ is marked up by 30% above its cost price and then sold at a ...
The cost price of 30 apples is Rs.120. If it is sold at 25% profit, then how many apples will be sold for Rs.70?
Profit percentage received on a product when sold for Rs.500 is equal to the percentage loss incurred when the same product is sold for Rs.300. Find the...