Favor composition for flexibility and easier maintenance.
In object-oriented design, using composition over inheritance can lead to more flexible and maintainable code. Composition allows for assembling objects with various capabilities, which can be swapped out without affecting other parts of the code. For example, consider a 'PaymentProcessor' class in an e-commerce setting. Instead of subclassing it for each payment type like 'CreditCardProcessor' or 'PayPalProcessor', you can compose it with different 'PaymentStrategy' objects. This way, adding a new payment method only involves creating a new strategy rather than altering the class hierarchy.
Additional Notes
How would you explain a common design judgment when deciding between inheritance and composition in an interview?