Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3933562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:36:54+00:00 2026-05-19T23:36:54+00:00

Recently we discussed a defect mentioned here and one of the parties said something

  • 0

Recently we discussed a defect mentioned here and one of the parties said something like “yes, that’s why books say that inheritance should be avoided.

I’ve been using inheritance for years and find it very useful and convenient in many design cases. Also I’m sure that the person arguing at the very least misunderstood what those “books say”.

Is there really an idea that inheritance is kind of bad and should be avoided? Where does it originate and where can I learn more?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:36:54+00:00Added an answer on May 19, 2026 at 11:36 pm

    I think what he might have meant is that inheritance can be overused, even in cases where composition would be a better solution. This is discussed in several books, e.g.

    • Effective Java 2nd Edition, Item 16: Favor composition over inheritance

    Inheritance is a powerful way to achieve code reuse, but it is not always the best
    tool for the job. Used inappropriately, it leads to fragile software. It is safe to use
    inheritance within a package, where the subclass and the superclass implementations
    are under the control of the same programmers. It is also safe to use inheritance
    when extending classes specifically designed and documented for extension
    (Item 17). Inheriting from ordinary concrete classes across package boundaries,
    however, is dangerous. As a reminder, this book uses the word “inheritance” to
    mean implementation inheritance (when one class extends another). The problems
    discussed in this item do not apply to interface inheritance (when a class implements
    an interface or where one interface extends another).

    Unlike method invocation, inheritance violates encapsulation [Snyder86].
    In other words, a subclass depends on the implementation details of its superclass
    for its proper function. The superclass’s implementation may change from release
    to release, and if it does, the subclass may break, even though its code has not
    been touched. As a consequence, a subclass must evolve in tandem with its superclass,
    unless the superclass’s authors have designed and documented it specifically
    for the purpose of being extended.

    • Effective C++ 3rd Edition has several items related to this:
      • Item 32: Make sure public inheritance models “is-a.”
      • Item 34: Differentiate between inheritance of interface and inheritance of implementation
      • Item 38: Model “has-a” or “is-implemented-in-terms-of” through composition
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently discussed with a colleague about mocking. He said that mocking classes is
Until recently, I posted Python code (whitespace matters) to blogspot.com using something like this:
I recently ran into a piece of code very much like this one: var
Recently one of our app servers went down, when it was rebooted the Python
Recently, I was writing a class in which I discovered that I could reduce
I recently migrated one of my domains to a new hosting service, so I
I recently was asked this question in an interview and would like to hear
I was looking at a job posting recently and one of the requirements was
Does anyone know of any reliable (and, hopefully, extensive) books/websites that discuss GDI+ performance
A textbook I recently read discussed row major & column major arrays. The book

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.