Yes, that’s fine. This is an example of a template method template in which you use inheritance to define a method that supports the well-known "skeleton" but can have custom logic.
public abstract class Ancestor { protected virtual void CanOverrideThisStep(){...} protected abstract void MustDefineThisStep(); protected sealed void MustDoExactlyThis(){...} private void HideThisStepFromEveryone(){...} public sealed void TemplateMethod() { ... CanOverrideThisStep(); ... MustDoExactlyThis(); ... MustDefineThisStep(); ... HideThisStepFromEveryone(); } }
Inheriting ancestors above must define a body for MustDefineThisStep () and can optionally override CanOverrideThisStep (), but cannot touch MustDoExactlyThis (), HideThisStepFromEveryone, or the TemplateMethod driving function itself. However, except HideThisStepFromEveryone, all subtopics are available for child classes, so the child can use MustDoExactlyThis () in the implementation of MustDefineThisStep ().
This is very common; such constructs are the reason that OO languages have access modifiers that are at their disposal. The template is very useful for workflows, file processing, and other tasks that are usually the same, but have slightly different implementation details.
Keiths
source share