Skip to content

Instantly share code, notes, and snippets.

@pparadis

pparadis/TemplateMethod.cs

Last active Aug 29, 2015
Embed
What would you like to do?
public class LinkGenerator
{
public string GetLink(string url, string title)
{
return string.Format(GetLinkFormatPattern(), url, title);
}
public virtual string GetLinkFormatPattern()
{
return "<a href=\"{0}\">{1}</a>";
}
}
public class BoldLinkGenerator : LinkGenerator
{
public override string GetLinkFormatPattern()
{
return "<strong><a href=\"{0}\">{1}</a></strong>";
}
}
using System.Console;
public class Start
{
public static void Main(string[] args)
{
WriteLine(new LinkGenerator().GetLink("http://www.frenchcoding.com", "French Coding"));
WriteLine(new BoldLinkGenerator().GetLink("http://www.frenchcoding.com", "French Coding"));
ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment