title: Implement an Observer pattern in Dart
body: <p>I would like to implement an observer pattern in Dart but I'm not sure how to go about it.</p>
  
  <p>Let's say I have a class:</p>
  
  
  
  <pre class="lang-dart prettyprint-override"><code>class MyClass {
  
    String observed_field;
  
  }
  </code></pre>
  
  <p>Now, whenever I change the field, I'd like to print "observed_field changed" string into the console. Pretty simple to do with a custom setter:</p>
  
  <pre class="lang-dart prettyprint-override"><code>class MyClass {
  
    String _observed_field;
  
    get observed_field    =&gt; _observed_field;
    set observed_field(v) {
      _observed_field = v;
      print("observed_field changed");
    }
  
  }
  </code></pre>
  
  <p>Now, of course, if I have not one, but many of those fields, I wouldn't want to create all those getters and setters. The obvious theoretical solution is to have them dynamically added to the class with something like this (not a working code, just an example of how I wish it looked):</p>
  
  <pre class="lang-dart prettyprint-override"><code>class MyClass
  
    String  _observeable_field;
    String  _observeable_field_2;
  
    observe(#observeable_field, #observeable_field_2);
  
  end
  </code></pre>
  
  <p><strong>Is it even possible?</strong> Additionally, it would be super awesome to not have those fields defined above the <code>observe()</code> call, but rather  write something like:</p>
  
  <pre class="lang-dart prettyprint-override"><code>observe(String: #_observeable_field, String: #_observeable_field_2);
  </code></pre>
  
  <p>So that those fields are declared automatically.</p>