What is a major downside to using inheritance instead of composition?

Disable ads (and more) with a membership for a one time $4.99 payment

Prepare for the UCF COP3330 Object Oriented Programming Final Exam with comprehensive study guides and practice quizzes. Gain insights into exam format, key topics, and strategies to excel. Start your journey towards success today!

Using inheritance can indeed lead to tightly coupled code, which is a significant downside of this approach compared to composition. When classes are tightly coupled, they become interdependent, meaning that a change in one class can have a direct and often unintended impact on the other classes that inherit from it. This can make the codebase more fragile and harder to maintain, as changes in base classes can propagate through derived classes, necessitating careful consideration of how such changes might affect the system as a whole.

Composition, on the other hand, fosters a more flexible and modular design by allowing classes to be constructed from other classes, enabling easier changes and allowing for variations in behavior through containment rather than inheritance. This helps in adhering to design principles such as the Single Responsibility Principle and making the code more resilient to changes.

While other choices touch upon code readability, lines of code, and implementation difficulty, they do not accurately capture the conceptual drawback associated with the dependency relationships introduced by inheritance. Being tightly coupled is typically the standout concern among developers when considering the implications of inheritance versus a more compositional approach.