728x90 아이템11 1. 생성자 대신 정적 팩토리 메서드를 고려하라 * 다음과 같이 public 생성자 대신(or 함께) 정적 팩토리 메서드를 제공할 수 있습니다. Class Coffe{ private String name; private int price; public Coffee(String name, int price){//생성자 this.name = name; this.price = price; } public static Coffee Americano(){//정적 펙토리 메서드 return new Coffee("Americano", 4100); } public static Coffee Latte(){ return new Coffe("Latte", 4800); } } 장점 1. 이름을 가질 수 있어 반환될 객체의 특성을 쉽게 묘사할 수 있습니다. 2. 호출될 때마.. 2021. 8. 22. 이전 1 다음 728x90