정적 팩토리 메서드1 [Effective Java] 정적 팩토리 메서드 정적 팩토리 메서드 스태틱 메서드로 객체 생성을 캡슐화한다. 장점 이름이 있기에 가독성이 높다 인스턴스 생성 없이 가능하다. 반환 타입의 하위 타입으로도 반환이 가능하다. 객체 생성을 캡슐화할 수 있다. 1. 가독성이 높다. public class Coffee { int price, makeTime, calories; public Coffee(int price, int makeTime, int calories) { this.price = price; this.makeTime = makeTime; this.calories = calories; } public static Coffee newAmericano() { return new Coffee(4100, 5, 5); } public static Coffe.. 2021. 4. 7. 이전 1 다음 728x90