디자인 측면에서 고려해야 할 이론적 인 질문입니다. POJO를이 재사용 가능한 클래스로 대체한다면 어떨까요? 일부 상용구 코드는 피할 수 있지만 어떤 문제가 발생할 수 있습니까?클래스 속성을 HashMap으로 대체하는 데 문제가 있습니까?
// Does not include failsafes, guards, defensive copying, whatever...
class MySingleGetterAndSetterClass{
private HashMap<String,Object> myProperties;
public SingleGetterAndSetter(String name){
myProperties = new HashMap<String,Object>();
myProperties.put("name", name);
}
public Object get(string propertyName){
return myProperties.get(propertyName);
}
public Object set(string propertyName, Object value){
myProperties.put(propertyName, value);
}
}
은 당신의'set' 방법은'get' 호출하는 건가요? –
Nope. 결정된. 이 메모장에 쓴 : P –
브라우저의 코드 검사기가 최고되지 않습니다) –