简体   繁体   中英

Preventing access to base method from derived class

Given the following classes structure, is there a way to prevent BaseMethod() from being called or seen from FinalClass ?

public abstract class BaseClass
{
    protected virtual void BaseMethod()
    {
    }
}

public class IntermediateClass : BaseClass
{
    protected sealed override void BaseMethod()
    {
        base.BaseMethod();
    }

    private void IntermediateMethod()
    {
        BaseMethod();
    }
}

public class FinalClass : IntermediateClass
{
    protected void FinalMethod()
    {
    }
}

You could make BaseMethod internal and place FinalClass in a different assembly to BaseClass and IntermediateClass .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM