Skip to content
Discussion options

You must be logged in to vote

it would be nice if a virtual method intended to be called by the overrides was likewise enforced as a compiler warning, at minimum.

This would be a space for analyzers for your domain-specific additional rules you would like to have.

That said, the way i generally handle this is to never make it necessary for the override to call into the base. Indeed, anything that must run is designed to be impossible not to run. The override only exists for the part that is ok to be overridden without the base happening.

In other words. INstead of:

public virtual void Foo()
{
    This.MustRun();
    This.DoesNotHaveTo();
}

I instead write:

public void Foo()
{
    This.MustRun();
    OptionalFooPart…

Replies: 6 comments 27 replies

Comment options

You must be logged in to vote
18 replies
@theunrepentantgeek
Comment options

@CyrusNajmabadi
Comment options

@najak3d
Comment options

@najak3d
Comment options

@CyrusNajmabadi
Comment options

Answer selected by najak3d
Comment options

You must be logged in to vote
1 reply
@FaustVX
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@najak3d
Comment options

@najak3d
Comment options

@HaloFour
Comment options

@najak3d
Comment options

@CyrusNajmabadi
Comment options

Comment options

You must be logged in to vote
1 reply
@CyrusNajmabadi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants