|
| 1 | +package chain; |
| 2 | + |
| 3 | +import chain.dto.ApprovalRequestDto; |
| 4 | +import chain.enums.RequestType; |
| 5 | +import chain.handler.ApprovalHandler; |
| 6 | +import chain.processor.CEO; |
| 7 | +import chain.processor.DepartmentManager; |
| 8 | +import chain.processor.HRManager; |
| 9 | + |
| 10 | +public class App { |
| 11 | + public static void main(String[] args) { |
| 12 | + // Chain:deptManager -> hrManager -> CEO |
| 13 | + ApprovalHandler deptManager = new DepartmentManager(); |
| 14 | + ApprovalHandler hrManager = new HRManager(); |
| 15 | + ApprovalHandler ceo = new CEO(); |
| 16 | + |
| 17 | + deptManager.linkWith(hrManager).linkWith(ceo); |
| 18 | + |
| 19 | + // Different scene requests |
| 20 | + ApprovalRequestDto r1 = new ApprovalRequestDto(RequestType.LEAVE, "Alice", 0, 2); |
| 21 | + ApprovalRequestDto r2 = new ApprovalRequestDto(RequestType.EXPENSE, "Bob", 800, 0); |
| 22 | + ApprovalRequestDto r3 = new ApprovalRequestDto(RequestType.PURCHASE, "Charlie", 5000, 0); |
| 23 | + ApprovalRequestDto r4 = new ApprovalRequestDto(RequestType.LEAVE, "David", 0, 10); |
| 24 | + |
| 25 | + System.out.println("--- Start processing requests ---"); |
| 26 | + System.out.printf("--- r1 start [%s]---%n", r1.getType()); |
| 27 | + deptManager.handle(r1); |
| 28 | + System.out.printf("--- r1 end [%s]---%n", r1.getType()); |
| 29 | + System.out.printf("--- r2 start [%s]---%n", r2.getType()); |
| 30 | + deptManager.handle(r2); |
| 31 | + System.out.printf("--- r2 end [%s]---%n", r2.getType()); |
| 32 | + System.out.printf("--- r3 start [%s]---%n", r3.getType()); |
| 33 | + deptManager.handle(r3); |
| 34 | + System.out.printf("--- r3 end [%s]---%n", r3.getType()); |
| 35 | + System.out.printf("--- r4 start [%s]---%n", r4.getType()); |
| 36 | + deptManager.handle(r4); |
| 37 | + System.out.printf("--- r4 end [%s]---%n", r4.getType()); |
| 38 | + |
| 39 | + System.out.println("--- Request processing completed ---"); |
| 40 | + } |
| 41 | +} |
0 commit comments