What is the best practice in implementing/providing getters/setters for a class containing a map?
The most common implementation I see is:
public class MyClass { private Map<String, String> myMap; public getMyMap() { /* Return an unmodifiable map */ } public setMyMap(Map<String, String> myMap) { ... } } Or would it be better to provide an interface like:
public getMyMap() { /* Return a modifiable map */ } public addToMap(String key, String value) { myMap.put(key, value); } And why is such method better?