(임시) 클래스 보단 인터페이스 방식으로

				자바 컬렉션 프레임워크 계층 다이어그램


왜 컬렉션 프레임워크를 사용할때 명확한 클래스보다 인터페이스를 쓰는게 더 좋은방향일까?

// 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

좋은 웹페이지 즐겨찾기