mardi 1 mars 2016

What is the name of this inheritance design pattern?

Instead of having a public virtual method, you have a public sealed method that calls a protected virtual method. Something like this:

public class Test {

    public void DoStuff(){
        // Do stuff here...
        ProtectedDoStuff();
        // Do more stuff...
    }

    protected virtual void ProtectedDoStuff(){
        // Do stuff...
    }
}

Instead of:

public class Test {

    public virtual void DoStuff(){
        // Do stuff here...
        // Do a lot of stuff...
        // Do more stuff...
    }
}

public class Test2 : Test {

    public override void DoStuff(){
        // Do same stuff as base
        // Do different stuff
        // Do more stuff just like base
    }
}

This avoid having to re-implement all the functionality from the public method if it will be needed all time. I know this has already been asked on stackoverflow but I can't find the question.

Aucun commentaire:

Enregistrer un commentaire