I frequently find myself creating classes which use this form (A):
abstract class Animal {
public void Walk() {
// TODO: do something before walking
/
Methods are means of taking action and going by that rule method names should be either verb or verb phrases.And its applicable to methods irrespective of where they are declared.For me Dog.Walk looks more natural than Dog.WalkInternal.And yes naming of method is more of a guideline than a design pattern :).If you are a .Net guy , then I will recommend "Framework Design GuideLines" book by Brad Adam and Krzystof Cwalina , which clearly address such problems.
One name for this pattern is "Template Method Pattern"
In C#, the method to be overridden by a derived class is preceded by "On". The logic behind this naming is that the derived class is custom responding to what is conceptually an internal event. This led to some confusion with C#'s other, now deprecated, use of "On" for raising events, but that's an old C# specific problem and it doesn't really exist anymore.
class BaseClass
{
protected virtual void OnInitialize() {};
private PreInitialize() {}
private PostInitialize() {}
void Initialize()
{
PreInitialize();
OnInitialize();
PostInitialize();
}
}
class DerivedClass : BaseClass
{
protected override void OnInitialize() { /*do whatever*/ }
}