策略模式:封装的是做一件事不同的执行方式,本质上依旧是多态
package strategy; public interface Comparator<T> { int compare(T o1, T o2); }
package strategy; public class DogComparator implements Comparator<Dog>{ @Override public int compare(Dog o1, Dog o2) { if (o1.food < o2.food) return -1; else if (o1.food > o2.food) return 1; return 0; } }