[cap-talk] Singletons Considered Harmful
David Wagner
daw at cs.berkeley.edu
Wed Mar 31 16:53:09 PDT 2010
Raoul Duke wrote:
>-> "When an object method calls another self-object method that uses
>private instance data, it effectively has an input which is not
>declared in its interface. This can be confusing; callers can no
>longer tell from the interface alone what resources the method might
>access."
I would say that the input is declared in its interface: it's the receiver
(the "this" parameter). In the call
foo.m(),
it's the foo. Callers can tell that foo.m() might access all of the
private instance state of foo. Of course the interface abstracts out the
details of how the private state of foo is represented. But the type
signature of m includes the types of all arguments, and the type of
the receiver (the type of the object that m is attached to); the
private instance data of foo is represented in m's type signature
by the receiver type.
In contrast, if there are gazillions of mutable global variables,
then we'd have to say that
foo.m()
implicitly receives access to all of those global variables, and
those global variables are not represented in the interface or type
signature of m.
It may just be a quantitative difference (a difference in magnitude),
but the difference is large enough to (I would assert) make this a
qualitative difference in practice.
More information about the cap-talk
mailing list