Question
Which SOLID principle emphasizes that software entities
should be open for extension but closed for modification?Solution
The Open/Closed Principle (OCP) is one of the SOLID principles for object-oriented design. 1. Key Idea: Software entities like classes, modules, and functions should be extendable without altering existing code. 2. Implementation: Achieved through techniques like inheritance, polymorphism, or interfaces that allow new functionality to be added without modifying the original codebase. 3. Benefits: Promotes code reusability, reduces the risk of introducing bugs into stable code, and facilitates easier maintenance and scaling. 4. Example: A class for processing payments could use an interface for payment methods. Adding a new payment type would require extending the interface, not modifying the class. This principle ensures that software systems are adaptable to new requirements without jeopardizing existing functionality. Why Other Options Are Incorrect: • A) SRP: Focuses on assigning one responsibility to each class/module but does not address extensibility. • C) LSP: Ensures derived classes can replace base classes without altering behavior, unrelated to modification. • D) ISP: Advocates for creating specific interfaces for clients, reducing unnecessary dependencies. • E) DIP: Encourages high-level modules to depend on abstractions rather than concrete implementations.
162 unit of work can be completed by P alone in 27 days. P started working alone and joined by Q after 12 days such that they completed the remaining wo...
A and B can do a piece of work in 12 days and 18 days, respectively. They start working together, and after 4 days, A leaves the work. How many more day...
- Raj alone can complete a work in 25 days. Mohan is five times as efficient as Raj. Find the percentage of work completed by Raj and Mohan together in 5 day...
A and B individually can complete the work in 28 days and 42 days respectively. If the time taken by C alone to complete the work is 1.25 times the time...
If 24 persons can finish 50% of work in 12 days in how many days 48 person can finish the complete work?
The efficiency of C is 20% more than the efficiency of D. D alone can complete a piece of work in (y-2) days. The time taken by C alone to complete the ...
- If Arjun can complete his work in 28 days by working 4 hours a day, how many hours a day should he work to finish the same work in 16 days?
Dhamu can complete a task on his own in 10 days. When Dhamu collaborates with Gaja, they can finish the same task in 6 days. Determine the number of day...
A can complete a work in 40 days. B takes 20 days less than A to complete the same work. In how many days can both of them together complete 60% of the ...
N workers can complete a piece of work in 50 days. When 5 more workers joined, then the work got completed in 40 days, then what is the value of N?