Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 137
    This is not always a perfect approach, it's simply a good guideline. the Liskov Substitution Principle is much more accurate (fails less). Commented Sep 17, 2008 at 0:25
  • 51
    "My car has a vehicle." If you consider that as a separate sentence, not in a programming context, that makes absolutely no sense. And that's the whole point of this technique. If it sounds awkward, it is probably wrong. Commented Aug 14, 2011 at 18:27
  • 56
    @Nick Sure, but "My Car has a VehicleBehavior" makes more sense (I guess your "Vehicle" class could be named "VehicleBehavior"). So you cannot base your decision on "has a" vs "is a" comparision, you have to use LSP, or you will make mistakes Commented Aug 26, 2011 at 11:53
  • 46
    Instead of "is a" think of "behaves like." Inheritance is about inheriting behavior, not just semantics. Commented Mar 31, 2012 at 19:25
  • 15
    This doesn't answer the question. The question is "why" not "what". Commented Oct 20, 2017 at 10:57