title: About factory constructor in Dart
body: <p>Below is about a usage of factory constructor from Seth Ladd's blog ' <a href="https://www.dartlang.org/dart-tips/dart-tips-ep-11.html" rel="noreferrer">Dart - Trying to understand the value of 'factory' constructor'</a>.</p>
  
  
  
  <pre class="lang-dart prettyprint-override"><code>class Symbol {
    final String name;
    static Map&lt;String, Symbol&gt; _cache = new Map&lt;String, Symbol&gt;();
  
    factory Symbol(String name) {
      if (_cache.containsKey(name)) {
        return _cache[name];
      } else {
        final symbol = new Symbol._internal(name);
        _cache[name] = symbol;
        return symbol;
      }
    }
  
    Symbol._internal(this.name);
  }
  
  
  main() {
    var x = new Symbol('X');
    var alsoX = new Symbol('X');
  
    print(identical(x, alsoX));  // true
  }
  </code></pre>
  
  <p>IMHO, with general constructor, the same effect can be achieved with a subtle difference, but quite simpler. </p>
  
  <pre class="lang-dart prettyprint-override"><code>class Symbol {
    static final Map&lt;String, Symbol&gt; cache = {};
    final String name;
  
    Symbol(name) {
      cache[name] = new Symbol._internal();
    }
  
    Symbol._internal();
  }
  
  main(){
  var a = new Symbol('something');
  var b = new Symbol('something');
  
  print(identical(a, b)); // false!
  print(Symbol.cache); //{something: Instance of 'Symbol'}
  }
  </code></pre>
  
  <p>As shown above, though the two instances, a &amp; b, are different objects, the effect is all the same as shown in 'print(Symbol.cache); //{something: Instance of 'Symbol'}' as a map object permit only one of same strings as its key.</p>
  
  <p>So, my question was what are peculiar merits of factory constructor(or <strong>factory pattern</strong>) over general/const constructors? Because the above sample code alone shows no merit of factory constructor. </p>
  
  <p>Could anyone explain what is so called 'Factory Pattern' in Dart language rather than Java/C#? </p>