0
클래스 푸가있는 경우 해시 맵 예 :개체 필드의 메서드를 래핑하거나 개체 자체를 전달할시기는 언제입니까?
public class Foo {
private HashMap <String, Integer> fooMap;
//other foo methods
}
fooMap를 캡슐화 할 때, 아래와 같이 fooMap가 그 방법을 포장해야하는 상황 무엇 :
public class Foo {
private HashMap<String, Integer> fooMap;
//other foo methods
public int getFoo(String s) {
return fooMap.get(s);
}
//other wrapper methods
}
또는이 fooMap 자체 반환하여 필드를 노출 그것이 나쁜 생각을 일반적으로
public class Foo {
private HashMap<String, Integer> fooMap;
//other foo methods
public HashMap<String, Integer> getFooMap() {
return fooMap;
}
}