인터페이스

    [TIL - 20231228] Interface의 default 메서드를 활용한 Enum 확장

    💻문제점 Enum 값에 숫자 값을 넣어주기 위해 다음과 같이 setCalorie()를 선언했다. 문제는, OVER_INTAKE 밖에 사용되지 않는 메서드이기 때문에, 그 외에는 Enum의 message만 반환하는 점이 어색함이 많았다. NotificationMessage.java @Getter public enum NotificationMessage { // sse SSE_CONNECTION("SSE 연결이 완료되었습니다."), // intake OVER_INTAKE("오늘의 칼로리 섭취량이 %dKcal 초과되었습니다."); private final String message; NotificationMessage(String message) { this.message = message; } public ..

    [Kotlin] 클래스 상속, 추상화, 인터페이스

    객체 - 객체는 식별자(identity), 상태(state), 행동(behavior) 을 가진 실체 클래스 class Product // 필수 파라미터 지정 class Product constructor(val categoryLabe: String) // constructor 생성자가 한 개 있을 시 생략 가능 class Product(val categoryLabel: String) // constructor 생성자가 두 개 이상 일 시 (주 생성자, 부 생성자) class Product(val categoryLabel: String) { constructor(categoryLabel: String, name: String): this(categoryLabel) } // 파라미터에 디폴트 값이 존재한다면..