Cumulative
Leandro Motta Barros
lmb at stackedboxes.org
Wed Feb 26 05:28:58 PST 2014
Hello,
I'm coming late to the discussion, but I believe that you can use the
following idiom to achieve the same results in a different way:
class C
{
// This is not overridable
public final void doStuff()
{
doSomethingWhichNeverChanges();
doExtraStuff();
}
protected void doExtraStuff()
{
// This one can be overridden
}
}
Or did I miss something?
Cheers,
LMB
On Mon, Feb 24, 2014 at 5:41 AM, Steve Teale
<steve.teale at britseyeview.com>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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140226/b045d071/attachment-0001.html>
More information about the Digitalmars-d
mailing list