Template Method Pattern Code Review

Define the Country and Person Objects

Code Review

Code Walkthrough

The Person class (object) defines the structure for a person data object.

class Person : IComparable { public String Firstname { get; private set; } public String Lastname { get; private set; }
public Person(String firstName, String lastName) { this.Firstname = firstName; this.Lastname = lastName; } public int CompareTo(object obj) { Algorithm<Person> algoPerson = new Algorithm<Person>(); return(algoPerson.CompareTemplateMethod(this, obj)); } }

The Person class (object) contains the CompareTo() method, which will invoke the CompareTemplateMethod() method in the Template Method class.

The Country class (object) defines the structure for a country data object.

class Country : IComparable { public String CountryName { get; private set; }
public Country(String country) { this.CountryName = country; } public int CompareTo(object obj) { Algorithm<Country> algoCntry = new Algorithm<Country>(); return (algoCntry.CompareTemplateMethod(this, obj)); } }

The Country class (object) contains the CompareTo() method, which will invoke the CompareTemplateMethod() method in the Template Method class.