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.

6
  • 15
    I don't agree with that. You don't need to know the implementation details of the class you're inheriting from; only the public and protected members exposed by the class. If you have to know the implementation details, then either you or whoever wrote the base class is doing something wrong, and if the flaw is in the base class, composition won't help you fix/work around it. Commented Apr 4, 2011 at 23:15
  • 23
    How can you disagree with something you haven't read? There's a solid page and a half of discussion from GoF that you are getting just a tiny view of. Commented Apr 4, 2011 at 23:30
  • 7
    @pholosodad: I'm not disagreeing with something I haven't read. I'm disagreeing with what Dean wrote, that "By definition, you need to know the implementation details of the class you're inheriting from," which I have read. Commented Apr 4, 2011 at 23:47
  • 13
    What I wrote is just a summary of what's described in the GoF book. I might've worded it a little strongly (you don't need to know all the implementation details) but that's the general reason why the GoF says to favour composition over inheritance. Commented Apr 5, 2011 at 0:05
  • 2
    Correct me if I'm wrong but I see it as, "favor explicit class relationships (ie Interfaces) over implicit (ie inheritance)." The former tell you what you need without telling you how to do it. The latter not only tell you how to do it but will make you regret it down the road. Commented Apr 19, 2012 at 4:03