装饰者模式

//        //刚开始微信和支付宝都有支付和查询功能
//        PaymentInterface wechatPay = new WechatPay();
//        wechatPay.pay();
//        wechatPay.query();
//        PaymentInterface aliayPay = new AliayPay();
//        aliayPay.pay();
//        aliayPay.query();
//        //现在我想给支付宝添加一个退款功能,微信不需要。我不能在接口里面新增个退款方法(每个子类都要重写),这时候就可以用装饰者模式
//        DecoratorPay decoratorAliayPay = new DecoratorPay(new AliayPay());
//        decoratorAliayPay.pay();
//        decoratorAliayPay.query();
//        decoratorAliayPay.returnMoney();
//        DecoratorPay decoratorWechatPay = new DecoratorPay(new WechatPay());
//        decoratorWechatPay.pay();
//        decoratorWechatPay.query();
        //现在有了退款功能,还需要一个对账功能,这时候再新增个对账功能
        BillPay billPay = new BillPay(new DecoratorPay(new AliayPay()));
        billPay.pay();
        billPay.query();
        billPay.returnMoney();
        billPay.bill();
        //装饰模式的作用就是把父类定义为子类的参数,再不修改父类的前提下进行扩展,适配器是增加其他功能,会改变父类
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值