The template method template provides that the abstract base class does not have an overridable method: this method implements a general algorithm and should not be redefined in subclasses. In Java, a template method is declared finalin an abstract base class, in C # the keyword sealedhas a similar meaning, but no overridden method can not be declared sealed.
public abstract class Base
{
protected abstract AlgorithmStep1();
protected abstract AlgorithmStep2();
public sealed void TemplateMethod()
{
AlgorithmStep1();
AlgorithmStep2();
}
}
How can I solve this problem? Why can't you forbid a method to redefine subclasses (in C #)?
source
share