요소
인터페이스를 구현한 클래스는 인터페이스 타입으로 변수를 선언하여 인스턴스를 생성할 수 있음
인터페이스는 구현 코드가 없기 때문에 타입 상속이라고도 함
인터페이스는 주로 설계할 때 사용함
역할
public interface Scheduler {
void getNextCall();
void sendCallAgent();
}
public static void main(String[] args) throws IOException {
System.out.println("전화 상담원 할당 방식을 선택하세요");
System.out.println("R : 한명씩 차례대로");
System.out.println("L : 대기가 적은 상담원 우선");
System.out.println("P : 우선순위가 높은 고객우선 숙련도 높은 상담원");
int ch = System.in.read();
Scheduler scheduler = null;
if (ch == 'R' || ch == 'r') {
scheduler = new RoundRobin();
} else if (ch == 'L' || ch == 'l') {
scheduler = new LeastJob();
} else if (ch == 'P' || ch == 'p') {
scheduler = new PriorityAllocation();
} else {
System.out.println("지원되지 않는 기능입니다.");
return;
}
scheduler.getNextCall();
scheduler.sendCallAgent();
}
인터페이스 Scheduler를 RoundRobin, LeastJob, PriorityAllocation등으로 구현체로 만들어서 상황에 맞게(다형성) 사용할 수 있다.
인터페이스는 구현 코드가 없어서 하나의 클래스가 여러 인터페이스를 구현할 수 있음 [동시 상속 가능]
디폴트 매서드의 이름이 중복되는 경우에는 재정의 함.
자바 객체지향 프로그래밍 - 16 [컬렉션 프레임워크(List, Stack, Queue)] (0) | 2023.01.23 |
---|---|
자바 객체지향 프로그래밍 - 15 [Object] (2) | 2023.01.13 |
자바 객체지향 프로그래밍 - 13 [추상클래스(abstract)] (0) | 2023.01.11 |
자바 객체지향 프로그래밍 - 12 [다운 캐스팅과 instanceof] (0) | 2023.01.10 |
자바 객체지향 프로그래밍 - 11 [다형성] (0) | 2023.01.10 |