When to Use and When Not to Use Inheritance

When inheritance was first introduced into some other languages, it caused problems as users went too far, creating deep and overly complex inheritance trees. Inheritance is powerful and useful, but should not be overdone. I remember working with a developer. He spent an entire day working on the design of objects and finally said, “I can't figure out where to use polymorphism.” My suggestion was that if he couldn't find where to use it, maybe he didn't need to.

There are actually three ways to build an object model:

  • Encapsulation— If you want to use functionality from an object, but not really look like the object or override its functionality, don't inherit; instead, encapsulate an instance of the ...

Get A Programmer's Introduction to Visual Basic® .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.