News for hackers. Stuff that matters.
Re:Message Passing, Duck Typing, Object Composition, and not... by joe_the_user on Saturday January 01, 2011 @07:13PM (#2058906)
Indeed.

I recently replaced a containment relationship with an inheritance relationship.

Sometimes inheritance does make sense yet despite it being the least-bad "tool for the job", it seems awkward, fragile and ill-thought-out. You have some attributes hidden in the parent and attributes right there in the child. The idea that the ontological relationships "is-a", "has-a" etc should map cleanly to the class as buckets-of-functions-and-attributes isn't always correct and muddies the water IMHO.

I wish that there was something that worked like inheritance but was better. Perhaps a system of passing interfaces from objects to the object they contain would make things clearer and more flexible.

Re:Message Passing, Duck Typing, Object Composition, and not... by timr on Saturday January 01, 2011 @08:18PM (#2059044)
"it seems awkward, fragile and ill-thought-out"

Or, you know...not. Sometimes, inheritance is the perfect abstraction for the job, neither awkward nor fragile, but perfectly elegant. Which was my point.

When you've got an is-a relationship, inheritance often makes sense, and encapsulation is frequently awkward. When you've got a has-a relationship, inheritance is frequently awkward. Just because you can find an awkward use of inheritance or a leaky abstraction doesn't mean that inheritance is awkward. It's a tool with limitations, and the world is a messy place. Containment isn't a magic bullet, either.

I honestly don't understand where the bias against concepts comes from. When the concept works, you use it. When it doesn't, you don't. It's engineering, not religion.

Re:Message Passing, Duck Typing, Object Composition, and not... by Rusky on Saturday January 01, 2011 @08:05PM (#2059024)
"a system of passing interfaces from objects to the object they contain"

How is this not inheritance? You still have some attributes "hidden" in the contained object and some "right there" in the child.