C#C
C#•17mo ago
Marius 🗡

Is there a way to block the calling of public method from abstract class inside a derived one?

It makes sense to just not call it, but is there a way to prevent it?

example:
public abstract class Abstract
{
    public void Launch() { } // calls some inner private methods belonging to the abstract class itself does work with its data.
}

public class Derived : Abstract
{
    private void SomeMethod()
    {
        Launch(); // <-- is it possible to block such call? 
    }
}

// i would use that launch method in other outer class that uses other specific derived classes and calls the launch method like this:

public class Foo()
{
    public void DoWork()
    {
        Launch<Derived>();
    }
 
    void Launch<T>() where T : Abstract
    {
        Abstract specificClass = (T)Activator.CreateInstance(typeof(T));
        specificClass.Launch();
    }
}
Was this page helpful?