Topic: Addition: Per-function "friend-like" access control.


Author: herbs@interlog.com (Herb Sutter)
Date: 1995/05/21
Raw View
It's late, I'll post more later, but to get the ball rolling...

Motivation:

It would be very useful to be able to specify which clients are allowed to
access which methods.  For example, I would like language support for saying
something like: "Class A [and derivatives] can invoke Class X's methods
X::MethodOne and X::MethodTwo, Class B [&deriv] can invoke Class X's method
X::MethodSeven, and no one else can access anything in X."  Has this been
considered by the committee in the past?  (I know that you can simulate this
by using RTTI in every affected method to check/switch on the static type of
the caller, but that puts an enormous burden on the implementor and as such
is quite fragile and a poor substitute for language support.  Another
workaround involves using friendship but fails for several reasons, mainly
that friendship is on a per-class basis and that it's not inherited.)

What's my immediate motivation?  An upcoming methodology book whose
manuscript I'm reviewing for the publisher would benefit enormously from
language support for this feature.  I can see many other possible valid uses
that can't easily be obtained without requiring the programmer to use RTTI
in every function to control access.  I know that X3J16 and WG21 tend to
leave out even "good" extensions that can be worked around using existing
features, but in this case the cost of the workaround seems to be high in
terms of both effort and fragility of the resulting implementation.

Any thoughts from the ANSI/ISO members who frequent this oasis of light?
:-)

Thanks in advance,

Herb


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herb Sutter                 2228 Urwin, Ste 102         voice (416) 618-0184
Connected Object Solutions  Oakville ON Canada L6L 2T2    fax (905) 847-6019