Strategy Pattern

_config.yml

public class Context {

    public void pay(Payment payment) {
        payment.pay();
    }
}

public class Demo {
    
    public static void main (String[] args) {
    
        Payment p = new AliPay();
        Context context = new Context();
        context.pay(p);
    }
}

Collections.sort(List<T> list, Comparator<? super T> c) is an example of strategy pattern.

Written on July 22, 2018