When would you use composition instead of inheritance for retry behavior?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
Wrap a service with a retry component rather than making every retrying service inherit from a retry base class. The wrapper can accept a retry policy, backoff strategy, and clock, making behavior reusable and testable. Retry only operations whose semantics permit it, apply a total time budget, and add jitter to reduce synchronized traffic. Composition lets retry behavior vary independently of the service implementation. A retry wrapper must preserve meaningful errors and cancellation rather than hiding persistent failures behind unlimited attempts.
Related Questions in Software Engineering & OOP
Explain the SOLID Principles of Object-Oriented Software Engineering with Examples
Intermediate level • 621 views
Explain ACID properties in relational databases and how different Transaction Isolation Levels prevent concurrency anomalies.
Intermediate level • 151 views
How does encapsulation protect an object’s rules? Explain using a bank account.
Easy level • 1 views
How do abstraction and inheritance solve different problems?
Easy level • 1 views
What is the Liskov substitution principle, and why can a square-as-rectangle hierarchy violate it?
Medium level • 1 views