|
@@ -0,0 +1,21 @@
|
|
|
|
+package responsibilityPattern;
|
|
|
|
+
|
|
|
|
+import responsibilityPattern.entity.Order;
|
|
|
|
+import responsibilityPattern.handler.OrderHandler;
|
|
|
|
+import responsibilityPattern.handler.OrderPriceHandler;
|
|
|
|
+import responsibilityPattern.handler.OrderStockHandler;
|
|
|
|
+
|
|
|
|
+public class main {
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ OrderPriceHandler orderPriceHandler = new OrderPriceHandler();
|
|
|
|
+ OrderStockHandler orderStockHandler = new OrderStockHandler();
|
|
|
|
+ Order order = new Order("1", 10000D, 0);
|
|
|
|
+ //先检查库存,在检查价格
|
|
|
|
+ orderStockHandler.setNextHandler(orderPriceHandler);
|
|
|
|
+ try {
|
|
|
|
+ orderStockHandler.handle(order);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|