execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(OrderData orderData) { double price = orderData.getPrice(); int quantity = orderData.getQuantity(); double discountRate = orderData.getDiscountRate(); String discountCode = orderData.getDiscountCode(); String specialOffer = orderData.getSpecialOffer(); return calculateTotal(price, quantity, discountRate, discountCode, specialOffer); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subtotal = applyDiscount(subtotal, discountRate); } subtotal = applyDiscount(subtotal, discountCode); if (Objects.isNull(specialOffer)) { subtotal = applySpecialProcessing(subtotal); } return subtotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode)) { return amount * 0.7; } else if ("silver".equals(discountCode)) { return amount * 0.8; } else if ("bronze".equals(discountCode)) { return amount * 0.8; } return amount; } private double applySpecialProcessing (double amount) { return amount + 20.0; } } public class OrderCalculator { public double execute(InputData inputData) { double price = inputData.getPrice(); int quantity = inputData.getQuantity(); double discountRate = inputData.getDiscountRate(); String discountCode = inputData.getDiscountCode(); String specialOffer = inputData.getSpecialOffer(); return calculateTotal( price, quantity, discountRate , discountCode , specialOffer ); } private double calculateTotal (double price, int quantity, double discountRate , String discountCode , String specialOffer ) { double subtotal = price * quantity; if (quantity >= 5) { subTotal = applyDiscount( subTotal, discountRate ); } subTotal = applyDiscount( subTotal, discountCode ); if (Objects.isNull(specialOffer )) { subTotal = applySpecialProcessing( subTotal); } return subTotal; } private double applyDiscount (double amount, String discountCode ) { if ("gold".equals(discountCode )) { return amount * 0.7; } else if ("silver".equals(discountCode )) { return amount * 0.8; } else if ("bronze".equals(discountCode )) { return amount * 0.8; } return amount; } private double applySpecial (double amount) { return amount + 20.0; } } ※ChatGPTに生成してもらった特に意味のないコードです if (Objects.isNull(specialOffer )) { subTotal = applySpecial( subTotal); } 「値が null を取り得る」と いう知識が埋もれる 何に繋がるか? ・考慮漏れ ・重複コードの作成 ・知識の分散 多量のコードの中に 無造作に置かれると …