title: get/set methods and encapsulation in AS3
body: <p>I've often seen the following described as the "correct" way of implementing get/set methods:</p>
  
  <pre><code>public class Foo {
      private var _someVar:SomeClass;
  
      public function get someVar():SomeClass {
         return _someVar;
      }
  
      public function set someVar(newValue:SomeClass):void {
        _someVar = newValue;
      }
  }
  </code></pre>
  
  <p>Now, because AS3 is returning always references to Object classes, when we use the "get" method we obtain a reference to our <strong><em>private</em></strong> var => encapsulation is broken.</p>
  
  <p>Even if we don't have a set method we can modify the privar var !
  What is the purpose of setting it as private then? </p>
  
  <p>The only solution that I found to this is to return a clone of "_someVar" in our get method, but I've never seen this in any example.
  So I think I'm losing something here.</p>
  
  <p>Are you returning a clone object from your getters or you just accepting the break in encapsulation?</p>
  
  <p><strong>EDIT</strong>
  I understand how set and get methods works, and I understand the benefits of them.
  I'm asking for the break of "private" access in our private var when we return it with a getter by <strong>reference</strong> (if our var is of type Number, String, int, etc AS3 is returning always by value, not reference, so we don't have problem here).
  Maybe is not the encapsulation which is broken, because we can't set the property without a setter method. But we can modify it !</p>
  
  <p>See this example:</p>
  
  <pre><code>public class Foo {
      private var _someVar:Array; // note that this is a Object (not Number, String, etc)
  
      public function Foo(){
          _someVar = ['don't touch this!'];
      }
  
      public function get someVar():SomeClass {
         return _someVar;
      }
  
      // note that we don't have a setter
  
  }
  
  
  var f:Foo = new Foo(); 
  var a:Array = f.someVar;
  trace(a[0]); //  'don't touch this!'
  a[0] = 'why not?'; 
  trace(f.someVar[0]); // 'why not' 
  </code></pre>
  
  <p>So, we are changing our private var from outside, and without control, even when we don't have a setter method.</p>