Template Method Pattern Code Review
Define the Country and Person Objects
Code Review
- Template Method Pattern Code Review: Define the Pattern Interface and Handler Objects
- Template Method Pattern Code Review: Define the Country and Person Objects
- Template Method Pattern Code Review: Use the Template Method Pattern
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)); } }
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)); } }
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.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!