컴퓨터/이론: 개발
[2017.08.15] 09. 인터페이스(interface)
heepie
2017. 8. 15. 15:07
인터페이스(Interface)를 사용하는 이유는 http://heepie.tistory.com/20 이다.
Interface는 명세서와 같다.
Interface를 구현하는 클래스는 반드시 해당 메소드들을 구현해야한다.
장점
- 개발자 간 신뢰성을 확보 할 수 있다.
규칙
- 인터페이스의 접근 제어자는 반드시 public이어야 한다.
인터페이스를 구현한 클래스를 어떻게 조작할까 규정하기 때문에 모두가 접근 가능한 public이어야 한다.
public을 명시하지 않아도 public으로 인식한다.
- 인터페이스 간의 상속이 가능하다.
123456789101112131415161718192021interface LocationGettable {public String getLocation(String userId);}interface AgeGettable extends LocationGettable {public int getAge(String userId);}class UserInfoManager implements AgeGettable {@Overridepublic String getLocation(String userId) {// TODO Auto-generated method stubreturn null;}@Overridepublic int getAge(String userId) {// TODO Auto-generated method stubreturn 0;}}cs
#인터페이스 #interface