Add template method example
This commit is contained in:
44
src/TemplatePattern/WorkersExample/Worker.cs
Normal file
44
src/TemplatePattern/WorkersExample/Worker.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TemplatePattern.WorkersExample
|
||||
{
|
||||
/// <summary>
|
||||
/// Framework class
|
||||
/// </summary>
|
||||
public abstract class Worker
|
||||
{
|
||||
public void StartWorking()
|
||||
{
|
||||
WakeUpAndDrinkCoffee();
|
||||
TakeAShower();
|
||||
GetDressed();
|
||||
GoToWork();
|
||||
Work();
|
||||
}
|
||||
|
||||
protected virtual void WakeUpAndDrinkCoffee()
|
||||
{
|
||||
Console.WriteLine("Wake up and drink coffee normally");
|
||||
}
|
||||
|
||||
protected virtual void TakeAShower()
|
||||
{
|
||||
Console.WriteLine("Take a shower");
|
||||
}
|
||||
|
||||
protected virtual void GetDressed()
|
||||
{
|
||||
Console.WriteLine("Get dressed");
|
||||
}
|
||||
|
||||
protected virtual void GoToWork()
|
||||
{
|
||||
Console.WriteLine("Go to work");
|
||||
}
|
||||
|
||||
protected abstract void Work();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user