How to ensure that builder pattern is completed?

后端 未结 7 1674
鱼传尺愫
鱼传尺愫 2021-02-05 13:38

EDIT: I am not worried about being called in the wrong order since this is enforced through using multiple interfaces, I am just worried about the terminal method getting called

7条回答
  •  心在旅途
    2021-02-05 14:27

    Apply the new permission in a separate step that first validates that the Builder was constructed correctly:

    PermissionBuilder builder = permissionManager.grantUser( userId ).permissionTo( Right.READ ).item( docId ).asOf( new Date() );
    permissionManager.applyPermission(builder); // validates the PermissionBuilder (ie, was asOf actually called...whatever other business rules)
    

提交回复
热议问题