Method and apparatus for encapsulating a reference to a method in
object-based programming systems and ensuring that the reference is safe
are disclosed. The method of encapsulation provides for: a) defining an
entity that defines the shape of the method to be referenced; b) obtaining
a reference to a method; c) storing this reference in arbitrary data
structures; d) passing the reference to code written by other parties; e)
enabling invocation of the method by anyone holding the method reference;
and f) enabling the holder of a method reference to determine the target
object and method being referenced. These objectives are achieved in a
strongly typed manner, making it possible for: a) developers to learn of
type mismatch problems early (at compile-time) rather than late (at
run-time); and b) development tools to present information to developers
about the shape of components that use delegates. In addition, a model of
event based programming is disclosed, wherein event-related code can be
encapsulated in delegates.