
Interface
장치와 장치를 연결하는 기능, 수단을 의미하는 용어
OOP에서 Interface란
클래스와 클래스간 통신을 하기 위한 기능을 정의한 자료구조이다.
- Class사용자에게 Class의 기능 명세를 제공한다.
- 기능명세의 제공은 사용자에게 Class를 편하게 사용하도록 돕는다.
- 기능명세의 제공은 해당 기능이 반드시 구현된다는 약속을 전제한다.
Interface 생성
- Class의 사용자 측면 : Printing을 하기 위해 print를 호출.
- Class의 개발자 측면 : Printing이 가능한 Class는 반드시 print를 구현해야한다.
- Interface는 내부적으로 상속 mechanism을 사용.

interface orderable{
public boolean putMoney(int money);
}
public class vendingMachine implements orderable{
public boolean putMoney(int money){
return true;
}
public static void main(String[] args) {
//제공하는 Interface만 사용하겠다.
orderable v = new vendingMachine();
v.putMoney(100);
}
}
Interface의 특징
- Interface라는 목적성에 의하여 pulbic으로 처리 한다.

- Interface에서는 변수선언은 하지 못하지만 static final은 가능하다.

- Static Method를 선언하고 구현 할 수 있다.

Interface Inheritance
Interface는 Inheritance가 가능하다.
아래 코드에서 ColorPrinting을 추가로 지원한다고 했을 때 단순히 PrintColorDoc()을 추가 하면문제가 발생한다.
기존 개발된 프린터에 PrintColorDoc()를 구현해야 하는 문제가 발생한다.
따라서 이를 Interface Inheritance로 해결한다.

기존 코드는 그대로 두고 Inheritance하여 새로운 Interface를 선언한다.

Multiple Interface

- Printable, Scanable 두개의 Interface를 다중으로 구현.
- Inheritance도 같이 코딩 가능.
- public class HPPPrinter extends HPScanner implements Printable, Scanable 로 구현
InstanceOf Arithmatic of the Interface
Interface를 구현한 Class에서 해당 Interface로 instanceOf Arithmatic을 수행하면 true를 리턴한다.
이를 통해 해당 class가 어떤 Interface를 구현하였는지 구별한다.

Abstract Class
하나 이상의 Abstract Method를 가지고 있는 Class.
Abstract Class는 Instance를 만들 수 없으며 Inhertance 전용으로만 사용.

'JAVA' 카테고리의 다른 글
[Java] Array of Objects (abstract) (0) | 2022.06.15 |
---|---|
[Java] Polymorphism of Parameters (매개변수의 다형성) (2) | 2022.06.14 |
[Java] Inheritance (상속) (0) | 2022.06.08 |
[Java] 숫자 검사하기. (0) | 2022.06.07 |
[Java] Console I/O (0) | 2022.06.07 |