dimanche 1 décembre 2019

Template method pattern issue

if I have an abstract Parent class which has a templateMethod and a concrete Child class :

abstract class Parent
{
    final void templateMethod()
    {
        foo();
    }

    abstract void foo();
}

class Child extends Parent
{
    @Override
    void foo()
    {
        System.out.println("foo");
    }
}

what should i do if i only want the user to know that templateMethod and do not want to expose foo method to class Child's user while let the Child class define the implementation of foo method ? Or, is template method not suitable in this case? Then, is there any other strategies i can use?

Aucun commentaire:

Enregistrer un commentaire