vendredi 26 mai 2017

Add partial implementation to abstract method

What is the best way to achieve a design where an abstract method is implemented but must also still require implementation from subclasses. This sounds very rusty at the moment so I will illustrate it:

abstract class Foo {
    abstract void update();
}

abstract class Bar {
    void update() {
        //Do something
        update_();
        //Do something else
    }

    abstract void update_();
}

So basically, I want a way to add some implementation to an abstract method without stopping it propagating. I feel that simply renaming the method will create unclean code.

What is the best way to approach this problem? Is it simply renaming the method? Or is this pattern best avoided altogether?

Aucun commentaire:

Enregistrer un commentaire