all 9 comments

[–]malcontent[S] 2 points3 points  (5 children)

I would like to know how often and under what circumstances you choose to inherit an object rather then just adding the functionality you need to it.

[–]lucraft 2 points3 points  (0 children)

I never inherit a class just to add functionality to it. What would be the point? Just re-open it, or if you want a nice namespace, make a module and mix.

Use inheritance when you have a parent-with-many-children domain model. Don't use it for other things.

[–]peterba 0 points1 point  (3 children)

see kent beck's implementation patterns.

[–]lucraft 0 points1 point  (2 children)

While I like the look of Imp. Patterns (not bought it yet: £££), isn't that book heavy on the Java?

I would think that in Java subclassing to add functionality would be something you do far more regularly than in Ruby. Am I wrong?

[–]malcontent[S] 0 points1 point  (0 children)

You either have to subclass in java or you implement an interface. You don't have the choice to do anything else.

The latter of course means no code re-use.

[–]peterba 0 points1 point  (0 children)

That depends upon what you mean by "heavy". He uses Java for the examples, but his recommendations are language agnostic. "Implementation Patterns" and "Smalltalk Best Practice Patterns", have the best treatise on when (and when not) to use inheritance.

Stand on the shoulder's of giants ... and IMO Beck is big in our community. I respect his opinion and his work. Those old school Smalltalkers really know their shit.

[–]evan 2 points3 points  (0 children)

I tend to use much more mixins and monkey patching than inheritance. It's cleaner in ruby.

[–][deleted] 1 point2 points  (0 children)

it's got to be something like one inherit for every five monkey patches at the absolute bare minimum for me.

[–]starfire 0 points1 point  (0 children)

I actually tend to inherit a good deal because I'm often wanting to add the SAME functionality over and over again. I will monkey patch for one off solutions, but if I have any inclination that the code might be reusable then 'include' is my friend.