简单小例子——看结构图
public interface PayGateway { /** * 下单 */ void unifiedorder(); /** * 退款 */ void refund(); /** * 查询支付状态 */ void query(); /** * 发红包 */ void sendRedPack(); }
public class PayGatewayAdapter implements PayGateway { @Override public void unifiedorder() { } @Override public void refund() { } @Override public void query() { } @Override public void sendRedPack() { } }
public class ProductVideoOrder extends PayGatewayAdapter { @Override public void unifiedorder() { System.out.println("ProductVideoOrder unifiedorder"); } @Override public void refund() { System.out.println("ProductVideoOrder refund"); } }
public class ProductVipOrder extends PayGatewayAdapter { @Override public void unifiedorder() { System.out.println("ProductVipOrder unifiedorder"); } @Override public void refund() { System.out.println("ProductVipOrder refund"); } @Override public void sendRedPack() { System.out.println("ProductVipOrder sendRedPack"); } }
本文作者为DBC,转载请注明。