Gary Wright
2/14/2009 6:17:00 AM
On Feb 14, 2009, at 12:10 AM, Julian Leviston wrote:
> I thought operator overloading was a non-oop way of specifying
> multiple functions that each take different argument numbers? That's
> not what's going on here.
Agreed. This is not 'overloading' in the C++ sense of the term.
> This is messages having the same name exactly being sent to
> different classes having slightly different meanings depending on
> the class of the receiver. It's encapsulation, really... Each class
> encapsulates its meanings and can obviously have different meanings
> for the same method names depending on the classes in question.
Disagree. Encapsulation doesn't seem like the right concept to
describe this pattern.
I think that 'abstraction' might be a better description. When the
same method provides analogous semantics across multiple classes, the
method name becomes a sigil for the abstract semantics. So '<<' is a
sigil for 'alter via concatenation' (IO, String, Array) but is also a
sigil for 'shift to the left' (Fixnum, Date, IPAddr).
The term 'protocol' is often used to describe this sort of pattern
across classes.
Good library design comes from exploiting these sorts of patterns.
Gary Wright