Template Method
The Template Method is know as a behavioral pattern which lets subclasses implement behaviour that can vary. In the example below we use the Template Method to allow sub classes to implement how a hot drink is made.
A VB example of the Temple Method Pattern
Public Class MyPage
Public Sub Page_Load()
Dim CupOfTea As HotDrink
CupOfTea = New Tea
Dim CupOfCoffee As HotDrink
CupOfCoffee = New Coffee
MakeDrink(CupOfTea)
Response.write(".........<br/>")
MakeDrink(CupOfCoffee)
End Sub
Public Sub MakeDrink(ByVal HotDrink As HotDrink)
HotDrink.boilWater()
HotDrink.addIngredients()
HotDrink.addCondiments()
End SubEnd Class
Public Sub boilWater()
Response.write("Boiling Water...<br/>")
End Sub
Public MustOverride Sub addIngredients()
Public MustOverride Sub addCondiments()End Class
Inherits HotDrink
Public Overrides Sub addCondiments()
Response.write("Add Milk ...<br/>")
End Sub
Public Overrides Sub addIngredients()
Response.write("Add Tea Bags ...<br/>")
End SubEnd Class
Inherits HotDrink
Public Overrides Sub addCondiments()
Response.write("Add Milk ...<br/>")
End Sub
Public Overrides Sub addIngredients()
Response.write("Add Coffee Granules ...<br/>")
End Sub
End Class
UML