Posts Tagged ‘inheritance’

Reflection on OOP: Inheritance or Generalization

July 11th, 2011 No comments

As software engineers, we most likely have learned the three key characteristics of object oriented programming: inheritance, encapsulation, and polymorphism. Over the years I study and practice OOP, I realized that inheritance is out of date and arguably misleading, therefore should be replaced.

In OOP, inheritance refers to a relationship between two classes in which a subclass inherits the properties and methods of its super class. The term inheritance is not really a good one because

Squares Aren’t Rectangles? A Common Misunderstanding of Object Oriented Design From MSDN Magazine

December 5th, 2010 3 comments

While reading the recent Dec 2010 issue of MSDN magazine, I found an article (Multiparadigmatic .Net, Part 4: Object Orientation) with misunderstandings on object oriented design. I was surprised that the author reached conclusions like, “squares aren’t rectangles,” and “no happy ending here.” The conclusions are based on misunderstandings of object oriented design.

Let me show you what the root problem is and how to get a happy ending. After reading this, you won’t be bothered by “squares aren’t rectangles.”

What’s the problem?

As most people already know, inheritance or generalization (I prefer the latter) is an important feature of OOD. Using it effectively can lead to a good object model and concise codebase. In an inheritance relationship, a subtype must maintain “IS-A” relationship with its super type, for example, a Student type IS-A Person. I think most people are just fine with this.