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
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.
The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.