Guest MemberLanguage   English
Software Architecture · SOLID Principles

How would you answer an interview scenario involving composition over inheritance?

AdvancedUpdated 2026-08-09

For an interview scenario involving composition over inheritance, I would first clarify the business goal, scale, constraints, and the failure or quality attribute the interviewer wants to explore. Composition builds behavior by combining collaborators rather than relying on deep inheritance hierarchies. In this scenario, a notification base class has many conditional hooks for email, SMS, and push. Explain how composition could simplify it. For production, use inheritance for stable substitutable taxonomies and composition for behavioral variation and runtime assembly. I would then explain the main alternatives and tradeoffs, identify likely failure modes, and describe how I would validate the solution through testing, observability, security controls, and recovery or rollback planning.

#solid-principles#composition