Slide 25
Slide 25 text
© ZOZO, Inc.
25
public class 注文 {
// フィールド定義
// このファクトリメソッドが外部からの唯一のインスタンス化の方法
public static Either<失敗理由 , 注文> create(UUID userId, UUID productId, int
quantity){
if (!注文可能な商品である (productId)) return Either.left(失敗理由.商品が存在しない );
if (!注文可能な数量である (quantity)) return Either.left(失敗理由.数量が不正);
return Either.right(new 注文(UUID.randomUUID(), userId, productId, quantity));
}
}
Eitherを使った戻り値でドメインエラーを表現する
public enum 失敗理由 {
注文不可能な商品,
注文不可能な数量
}
列挙型