On Jan 5, 2006, at 12:12 PM, Adam S. wrote:
When do you guys choose to inherit from a class, use a delegate, or
As the saying goes, “Favor composition over inheritance.” The theory
there is simply that inheritance is a tighter coupling than
composition, so the latter handles change better. Delegation is a
form of composition.
Any Design Patterns book will have a detailed treatment of this very
What are some examples of common uses for Delegates or Forwardable?
Well, I wrote the documentation for both, and I must confess that I
still rarely use Delegate. It can think of one example where I
wanted full delegation and I wanted it for two classes, so I had to
roll my own anyway. The best example I can think of for it is
TempFile, in the standard library.
I use forwardable all the time, on the other hand. I love that
library. It allows me to control what gets delegated and rename
delegated methods. Good stuff. Two examples from my work would be
my solution-in-progress to the Ruby Test First Challenge and my
Hope that helps.
James Edward G. II