Files
excel-download/design-pattern/gof/src/FactoryMethod/before/ShipFactory.java
2021-11-05 23:37:47 +09:00

48 lines
1.3 KiB
Java
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package FactoryMethod.before;
public class ShipFactory {
public static Ship orderShip(String name, String email) {
// validate
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("배 이름을 지어주세요.");
}
if (email == null || email.isEmpty()) {
throw new IllegalArgumentException("연락처를 남겨주세요.");
}
prepareFor(name);
Ship ship = new Ship();
ship.setName(name);
// Customizing for specific name
if (name.equalsIgnoreCase("whiteship")) {
ship.setLogo("\uD83D\uDEE5");
} else if (name.equalsIgnoreCase("blackship")) {
ship.setLogo("");
}
// coloring
if (name.equalsIgnoreCase("whiteship")) {
ship.setColor("whiteship");
} else if (name.equalsIgnoreCase("blackship")) {
ship.setColor("black");
}
// notify
sendEmailTo(email, ship);
return ship;
}
private static void prepareFor(String name) {
System.out.println(name + " 만들 준비 중");
}
private static void sendEmailTo(String email, Ship ship) {
System.out.println(ship.getName() + " 다 만들었습니다.");
}
}