title: Avoiding setter to change value of class's property
body: <p>I have a class with one private field:</p>
  
  <pre><code>class Person {
    string name;
    public void setName(string name);
  }
  </code></pre>
  
  <p>Then, using some object which is responsible for interacting with user (in this example by command line), I want to change the value of this field:</p>
  
  <pre><code>Person somePerson;
  CommandLineView view;
  somePerson.setName(view.askUserForName());
  </code></pre>
  
  <p>It works. But I don't like using <code>set</code> function as it exposes class members.
  Therefore I started looking how to avoid it. </p>
  
  <p>New implementation looks like this:</p>
  
  <pre><code>class Person
  {
    string name;
    public void changeName(view) { name = view.askUserForName(); }
  }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>Person somePerson;
  CommandLineView view;
  somePerson.changeName(view);
  </code></pre>
  
  <p>Now <code>Person</code> does not expose its member. Moreover this class is responsible for logic related to changing name (for example function <code>changeName</code> could also update database, notify interested parties etc.</p>
  
  <p>The question is: Is such kind of refactoring a good practice? Or maybe implementation with <code>setter</code> was better, even if it break encapsulation?</p>