(임시) 클래스 보단 인터페이스 방식으로
자바 컬렉션 프레임워크 계층 다이어그램
왜 컬렉션 프레임워크를 사용할때 명확한 클래스보다 인터페이스를 쓰는게 더 좋은방향일까?
// Good - uses interface as type
List<Subscriber> subscribers = new Vector<Subscriber>();
//rather than this:
// Bad - uses class as type!
Vector<Subscriber> subscribers = new Vector<Subscriber>();
객체의 구현을 바꾸고 싶을때는 생성자만 다른 클래스의 이름으로 바꾸는 것이 가능하므로 훨씬 더 유연해질수 있다고 생각한다.
// If you get into the habit of using interfaces as types, your program will be much more flexible.
List<Subscriber> subscribers = new ArrayList<Subscriber>(...);
List<Subscriber> usbscribers = new LinkedList<Subscriber>(...);
레퍼런스
https://www.java-forums.org
http://jtechies.blogspot.com/2012/07/item-52-refer-to-objects-by-their.html
Author And Source
이 문제에 관하여((임시) 클래스 보단 인터페이스 방식으로), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@tmqthddl/임시-클래스-보단-인터페이스-방식으로저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)