[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: when should sends be virtual?

Rainer Blome writes:

> did anybody ever see a treatise about where and when it should be
> specified that a message send should be virtual?  at the send site?
> or at the declaration/implementation of a method?
> ever seen one of these answered?

One problem with letting the sender decide whether a call is virtual
(dispatched) or not is that it breaks encapsulation.  The receiver
should decide what happens with a message send, and statically binding
the send (e.g. to invoke an overriden method) is like writing instance
variables directly.  In other words, you can't reason about the
object's properties and invariants anymore by simply looking at the
object's definition.