void Start() { StrategyHuman h1 = new StrategyHuman("Yamada", 170, 60, 20); StrategyHuman h2 = new StrategyHuman("Sato", 175, 55, 20); comparator = new AgeComparator(); resultAge = Compare(h1, h2); comparator = new HeightComparator(); resultHeight = Compare(h1, h2); print("age :" + resultAge); print("height :" + resultHeight); }
public int compare(StrategyHuman h1, StrategyHuman h2) { if (h1.age > h2.age) { return(1); } else if (h1.age == h2.age) { return(0); } else { return(-1); } }
public int compare(StrategyHuman h1, StrategyHuman h2) { if (h1.height > h2.height) { return(1); } else if (h1.height == h2.height) { return(0); } else { return(-1); } }
public int Compare(StrategyHuman h1, StrategyHuman h2) { return(comparator.compare(h1, h2)); }