I have a problem with D
Stefan via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 28 02:52:57 PDT 2016
On Tuesday, 28 June 2016 at 04:37:34 UTC, Adam Sansier wrote:
> Hi,
>
> I have designed a class based system that involves
> self-delegation instead of override.
>
> It is similar to event based programming.
>
> I have defined an event as a container type that holds
> functions(or possibly delegates, but the desire is to avoid
> them).
>
Hi Adam,
The easiest way to enforce calling of base class's method is to
make it final and to offer additional functionality only in an
optional extra method:
class Base
{
alias EventMethod = void function(Base _this);
public Event!EventMethod MyEvents
final public MyEvent()
{
// Go ahead and inform subscribed handlers
MyEvents(this);
EventExtras(this);
}
protected void EventExtras() {} // empty in the base class
}
class Derived : Base
{
protected override void EventExtras()
{
// This does not need to call super.MyEvent
// Other work done here.
}
}
Does this help?
More information about the Digitalmars-d
mailing list