From 65929cf38c0e5b720ae38081b64c4fb3ffe99578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Sun, 30 Jul 2023 09:31:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=A3=85=E9=A5=B0=E5=99=A8=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=92=8C=E4=BA=AB=E5=85=83=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractAddFuncDecorator.java | 29 +++++++++++++++---- .../additionalDecorator/AddFuncDecorator.java | 11 +++++-- .../design/pay/factory/AddFuncFactory.java | 13 +++++---- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/study/design/pay/additionalDecorator/AbstractAddFuncDecorator.java b/src/main/java/com/study/design/pay/additionalDecorator/AbstractAddFuncDecorator.java index 9d9b49c..da55f77 100644 --- a/src/main/java/com/study/design/pay/additionalDecorator/AbstractAddFuncDecorator.java +++ b/src/main/java/com/study/design/pay/additionalDecorator/AbstractAddFuncDecorator.java @@ -3,22 +3,39 @@ package com.study.design.pay.additionalDecorator; import com.study.design.pay.pojo.PayBody; import com.study.design.pay.strategyContext.AbstractPayContext; +/** + * 装饰器抽象类 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/7/30 09:24 + */ public abstract class AbstractAddFuncDecorator extends AbstractPayContext { - // 这是我们的装饰器类。专门干装修的。 专门添加新功能的(平台币,红包) - // 装饰的是谁啊? 我作为一个称职的装饰器,我必须得知道装饰的是谁,不然我咋干活儿啊。 + /** + * 这是我们的装饰器类。专门干装修的。 专门添加新功能的(平台币,红包) + * 装饰的是谁啊? 我作为一个称职的装饰器,我必须得知道装饰的是谁,不然我咋干活儿啊。 + */ private AbstractPayContext abstractPayContext = null; public AbstractAddFuncDecorator(AbstractPayContext abstractPayContext) { this.abstractPayContext = abstractPayContext; } - // 开始干活儿 - //1. 老活儿。 支付。但是我又不能修改支付代码,也不能修改支付逻辑。 + /** + * 老活儿。 支付。但是我又不能修改支付代码,也不能修改支付逻辑。 + * + * @param payBody + * @return + */ @Override public Boolean execute(PayBody payBody) { return abstractPayContext.execute(payBody); } - //2. 老活儿不合适,没你装饰器照样能execute。 新活儿:平台币,红包) + /** + * 新活儿:平台币,红包 + * + * @param payBody + */ public abstract void additionalFunction(PayBody payBody); -} +} \ No newline at end of file diff --git a/src/main/java/com/study/design/pay/additionalDecorator/AddFuncDecorator.java b/src/main/java/com/study/design/pay/additionalDecorator/AddFuncDecorator.java index 072ec48..cb7cee9 100644 --- a/src/main/java/com/study/design/pay/additionalDecorator/AddFuncDecorator.java +++ b/src/main/java/com/study/design/pay/additionalDecorator/AddFuncDecorator.java @@ -5,19 +5,20 @@ import com.study.design.pay.strategyContext.AbstractPayContext; /** - * abstractPayContext 不是共享的,因为有的小伙伴选择 zfb 支付,有的小伙伴选择wx支付,等等。。。 + * abstractPayContext 不是共享的 * * @author : qinyingjie * @version : 2.2.0 * @date : 2022/9/27 02:20 */ public class AddFuncDecorator extends AbstractAddFuncDecorator { + public AddFuncDecorator(AbstractPayContext abstractPayContext) { super(abstractPayContext); } /** - * 新活儿 + * 复写方法:新活儿 * * @param payBody */ @@ -30,6 +31,12 @@ public class AddFuncDecorator extends AbstractAddFuncDecorator { System.out.println("更新平台币成功,发送红包到用户优惠券模块成功。"); } + /** + * 老活 新活 一起执行 + * + * @param payBody + * @return + */ @Override public Boolean execute(PayBody payBody) { // 算共享的。共享的调用逻辑 Boolean result = super.execute(payBody); //老活儿 diff --git a/src/main/java/com/study/design/pay/factory/AddFuncFactory.java b/src/main/java/com/study/design/pay/factory/AddFuncFactory.java index 2d04767..126c334 100644 --- a/src/main/java/com/study/design/pay/factory/AddFuncFactory.java +++ b/src/main/java/com/study/design/pay/factory/AddFuncFactory.java @@ -7,18 +7,19 @@ import com.study.design.pay.strategyContext.PayContext; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - /** - * 工厂类 + * 享元工厂类 * * @author : qinyingjie * @version : 2.2.0 * @date : 2023/7/29 09:11 */ public class AddFuncFactory { - // 工厂的目的是生产 AddFuncDecorator; 生产几个啊? 多个:享元 - // key 应该是能够和 AbstractAddFuncDecorator 做成对应的东西。 - // 这个map最多保存是三个对象。 + /** + * 工厂的目的是生产 AddFuncDecorator; 生产几个啊? 多个:享元 + * key 应该是能够和 AbstractAddFuncDecorator 做成对应的东西。 + * 这个map最多保存是三个对象。 + */ public final static Map maps = new ConcurrentHashMap<>(); public static AbstractAddFuncDecorator getAddFunc(PayContext payContext) { @@ -28,4 +29,4 @@ public class AddFuncFactory { } return maps.get(payContext); } -} +} \ No newline at end of file -- GitLab