Junior Java developers think they see inheritance opportunities in every class they build. It seems like a powerful construct, but the reality is that it can be extremely harmful when used improperly. Cameron Laird discusses this fact in his latest article, Against Inheritance: A Better Balance for Object Orientation.
"One fundamental aspect of OO expressiveness is class definitions in terms of inheritance. Some designers aim for inclusiveness and deep structure; they produce class hierarchies where everything is richly structured in terms of inheritance from carefully constructed base objects.
"I see a profound mistake in this, if a well-motivated one. Schoolroom exercises simplify real-world situations so that classes have only a few, simple relations to each other. This leads to the habit of thinking that class definitions must have logical relations to each other. Commercial coding deals with far messier situations, where the relationship between WireTransfer and CustomerEvent is ambiguous, at best. Many times, it’s wisest simply to leave a relationship unbound."
Read the full article: Against Inheritance: A Better Balance for Object Orientation.