1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package com.cyrgue.designpatterns.chain;
public class ConflictCheckerProgram {
private static ConflictChecker getChainOfConflicts(UserModel anonymous, UserModel registered){ ConflictChecker cartConflictChecker = new CartConflictChecker(anonymous, registered); ConflictChecker storeConflictChecker = new StoreConflictChecker(anonymous, registered); cartConflictChecker.setNextChecker(storeConflictChecker); return cartConflictChecker; }
public static void main(String[] args) { UserModel anonymous = userBuilder().cartId("1").shopId(1).build(); UserModel registered = userBuilder().cartId("2").shopId(2).build(); ConflictChecker checkerChain = getChainOfConflicts(anonymous, registered); try { checkerChain.check(); } catch (Exception e) { e.printStackTrace(); } }
private static UserModel.UserModelBuilder userBuilder() { return new UserModel.UserModelBuilder(); } }
|