|
@@ -0,0 +1,35 @@
|
|
|
+package templateMethodPattern.template;
|
|
|
+
|
|
|
+
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import responsibilityPattern.entity.Order;
|
|
|
+
|
|
|
+public abstract class OrderProcessTemplate {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(OrderProcessTemplate.class);
|
|
|
+
|
|
|
+ public final void processOrder(Order order) {
|
|
|
+ validateOrder(order);
|
|
|
+ needCoupon(order);
|
|
|
+ applyCoupon(order);
|
|
|
+ calculatePrice(order);
|
|
|
+ saveOrder(order);
|
|
|
+ }
|
|
|
+ //检查订单,子类必须重写
|
|
|
+ public abstract void validateOrder(Order order);
|
|
|
+ //计算价格
|
|
|
+ public abstract void calculatePrice(Order order);
|
|
|
+ //是否需要优惠券
|
|
|
+ boolean needCoupon(Order order) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //使用优惠券
|
|
|
+ void applyCoupon(Order order) {
|
|
|
+ log.info("default applyCoupon");
|
|
|
+ }
|
|
|
+ void saveOrder(Order order) {
|
|
|
+ log.info("default saveOrder");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|