Topic: Implicit functions sharing in hierarchies


Author: jrami@cs.huji.ac.il (Jeschek Rami)
Date: 16 Dec 1993 12:18:50 +0200
Raw View
I would like to suggets a new idea into the C++ language. I've run across many places
where a class is interested in performing it's own function and then calling the same
function of it's parent class and so on. This can be done implicitly only if you
use the constructor. If you need to do something that can not be done at compile time,
you need to call the parent function explicitly or create an entire hierarchy just for
this purpose.
I find this awkward to say the least. Such cases happen all too often and forcing the
programmer to state everything explicilty leaves room for errors and makes the code
look bad.
If we could declare an hierarchical function like

class A {
    public:
        hierarchical void Do_Some_Work () { cout << "Done general part"; };
....
}

class B : public A {
    public:
        heirarchical void Do_Some_Work () { cout << "Done my special part"; };
....
}

And then of course we could have a virtual hierarchical function which would mean calling
functions from the real class and up the hierarchy and passing paremeters and all.





Author: vaumont@tdsb-s.mais.hydro.qc.ca (Vincent Aumont)
Date: Fri, 17 Dec 1993 19:12:52 GMT
Raw View
Jeschek Rami (jrami@cs.huji.ac.il) wrote:
: I would like to suggets a new idea into the C++ language. I've run across many places
: where a class is interested in performing it's own function and then calling the same
: function of it's parent class and so on. This can be done implicitly only if you
: use the constructor. If you need to do something that can not be done at compile time,
: you need to call the parent function explicitly or create an entire hierarchy just for
: this purpose.
: I find this awkward to say the least. Such cases happen all too often and forcing the
: programmer to state everything explicilty leaves room for errors and makes the code
: look bad.
: If we could declare an hierarchical function like

: class A {
:     public:
:         hierarchical void Do_Some_Work () { cout << "Done general part"; };
: ....
: }

: class B : public A {
:     public:
:         heirarchical void Do_Some_Work () { cout << "Done my special part"; };
: ....
: }
What do you do in this case :

                    A
                  /  \
                 /    \
                B      C
                 \    /
                   \/
                    D

When D::Do_Some_Work is called which one is executed next ?
B::Do_Some_Work or C::Do_Some_Work ?
Of course you could specify the next function in D::Do_Some_Work's body
but your objective was to remove explicit calls from the function's body.

 Vincent.




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sun, 19 Dec 1993 00:34:27 GMT
Raw View
jrami@cs.huji.ac.il (Jeschek Rami) writes:

>I would like to suggets a new idea into the C++ language. I've run
>across many places where a class is interested in performing it's own
>function and then calling the same function of it's parent class and so
>on.

This idea is not new.  The commentary in ARM 10.1 refers to
this problem, which becomes even more cumbersome when virtual
base classes are used.

 ``Additional support for programming using multiple
   inheritance, such as the method combination schemes in some
   Lsip dialects, was considered.  None of the alternatives
   considered, however, seemed simple, general and efficient
   enough to justify the complexity they would add to C++.
   In particular, it was not obvious how to combine the C++
   strong static type checking with a scheme flexible enough
   to support directly the "mix-in" style of programming
   used in some Lisp dialects.''

--
Fergus Henderson        |   "People who brook no compromise in programming
                        |   languages should program in lambda calculus or
fjh@munta.cs.mu.OZ.AU   |   machine language, depending." --Andrew Koenig.