Topic: Delegation support


Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sun, 9 Jan 1994 22:51:36 GMT
Raw View
One very useful technique in programming is delegation,
but C++ doesnt support it very well: one has to write
horrible wrapper functions (or use operator->)

So here's an idea inspried by recent changes to C++ to
deprecate access declarations:

 struct Worker { void f(); };
 struct Boss {
  Worker *w;
  using *w;
  void g();
 };

 Boss b;
 b.f(); // calls (*a).f() == a->f()

Changes to "Worker" do not require "Boss" to be modified.

Delegation is like dynamic inheritance: changes to the
base or worker class will require a recompilation
when a derived or boss class are used.

However, unlike operator-> we have referential transparency:

 b.g(); // calls Boss function
 b.f(); // calls Worker function

Furthermore, the mechanism supports multiple delegation,
and allows local overriding functions to be written,
in a manner similar to inheritance.

After all, it is a form of inheritance.

Question: is this theoretically sound? (can encapsulation be violated?)

Question: is it useful? Useful enough to write an extension proposal?

Question: is it confusing for the average programmer?


--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA




Author: hendrik@vedge.com (Hendrik Boom)
Date: Thu, 13 Jan 1994 20:34:22 GMT
Raw View
maxtal@physics.su.OZ.AU (John Max Skaller) writes:
: One very useful technique in programming is delegation,
: but C++ doesnt support it very well: one has to write
: horrible wrapper functions (or use operator->)
...
...
:
: Question: is this theoretically sound? (can encapsulation be violated?)
:
That depends on whether you change the access rules.  If you define
delegation to be just what you would otherwise get with wrapper
functions, it is as sound as the language is now :-)

: Question: is it useful? Useful enough to write an extension proposal?

Yes. A large part of my code consists of wrappers for delegation.

:
: Question: is it confusing for the average programmer?
:

No more than 'with' in Pascal.  Or dir Pascal call it 'using' too?
I forget.

:
: --
:         JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
:  Maxtal Pty Ltd,      CSERVE:10236.1703
:         6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
:         NSW 2131, AUSTRALIA