lundi 29 juin 2015

Template method design pattern using Java 8

I want to refactor template method using java 8 new default method. Say I have a flow of process define in abstract class:

public abstract class FlowManager{
public void startFlow(){
    pahse1();
    pahse2();
}
public abstract void phase1();
public abstarct void pahse2();
}

and I have few subclass's that extend the above flow manager and each subclass implements its own phase1 and phase2 mathod. I wonder if its make any sense to refactor the code to an interface like this:

public interface FlowManager{
public default startFlow(){
    this.phase1();
    this.phase2();
}
public void phase1();
public void phase2();
}

What do u think? Thank u in advance

Aucun commentaire:

Enregistrer un commentaire