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