//The Algorithm class (object) represents the Template Method class containing the CompareTemplateMethod() method.
//The CompareTemplateMethod() invokes the CompareTo() method in the relevant IPrimitive subclass.
public class Algorithm<T>
{
private IPrimitive m_primitive;

public Algorithm()
{
if (GetType() == typeof(Algorithm<Person>))
{
m_primitive = new PersonPrimitive();
}

if (GetType() == typeof(Algorithm<Country>))
{
m_primitive = new CountryPrimitive();
}
}

public int CompareTemplateMethod(object objectA, object objectB)
{
return m_primitive.CompareTo(objectA, objectB);
}
}