Cumulative
qznc
qznc at web.de
Mon Feb 24 01:33:23 PST 2014
On Monday, 24 February 2014 at 08:41:06 UTC, Steve Teale wrote:
> 25 years ago, when I was trying to write some sort of library
> to go with Walter's C++ compiler, I had a wish, and it still
> pops into my head from time to time.
>
> What I wanted was functions that were declared in a base class
> as 'cumulative', or something similar. They would have been
> generally like virtual functions, except that any derived class
> that wanted to do something extra - as opposed to something
> different, would simply define an 'extend', and just specify
> the extra code. The compiler would then automatically add a
> call to the same function in whatever base class last defined
> or extended the method.
>
> extend void foo() // Declared in base class as cumulative
> void foo()
> {
> (cast(BaseClass) this).foo(); // Compiler does this for you
> // similar to changing a
> light bulb ;=)
>
> // the extra stuff
> }
>
> I think also that it might be necessary for the base class
> function to return on behalf of the derived method as opposed
> to to it.
>
> Does this make any sense?
>
> Steve
Sounds a little like the :after mechanism of the Common Lisp
Object System (CLOS). They also have :before, if your extra code
should run before the super-call. The third variant is :around,
which is like the default overwriting in D et. al.
More information about the Digitalmars-d
mailing list