title: Advantage of factory method pattern
body: <p>From <a href="https://en.wikipedia.org/wiki/Factory_method_pattern" rel="nofollow noreferrer">wiki</a>,</p>
  
  <p>The Factory Method design pattern solves problems like: </p>
  
  <ol>
  <li><p>How can an object be created so that subclasses can redefine which class to instantiate?</p></li>
  <li><p>How can a class defer instantiation to subclasses?</p></li>
  </ol>
  
  <p>For example, <code>MazeGame</code> provides the instantiation capability to subclass like <code>MagicMazeGame</code>.</p>
  
  <h2><a href="https://i.stack.imgur.com/80ZdT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/80ZdT.png" alt="enter image description here"></a></h2>
  
  <p>where,</p>
  
  <pre><code>public abstract class MazeGame {
      private final List&lt;Room&gt; rooms = new ArrayList&lt;&gt;();
  
      public MazeGame() {
          Room room1 = makeRoom();
          Room room2 = makeRoom();
          room1.connect(room2);
          rooms.add(room1);
          rooms.add(room2);
      }
  
      abstract protected Room makeRoom();
  }
  </code></pre>
  
  <hr>
  
  <p>Read <a href="https://stackoverflow.com/a/9141317/3317808">answer</a>.</p>
  
  <p>Of course, this is a creational pattern, so design should be around simplifying instantiation of a class.</p>
  
  <hr>
  
  <p>My question is, </p>
  
  <p>What is the advantage of <em>factory method pattern</em>, introducing <code>MagicGame</code> class that provides a template method(<code>public MazeGame(){..}</code>) and defer instantiation to subclass <code>MagicMazeGame</code> or <code>OrdinaryMazeGame</code>? </p>
  
  <p>Is <em>deferring instantiation to subclass</em> for only abstracting the below intricacies in a class like <code>MagicMazeGame</code>,</p>
  
  <pre><code>        Room room1 = MagicMazeGame();
          Room room2 = MagicMazeGame();
          room1.connect(room2);
          rooms.add(room1);
          rooms.add(room2);
  </code></pre>
  
  <p>and provide a uniform creation logic in every class <code>MagicMazeGame</code> or class <code>OrdinaryMazeGame</code>, as shown below,</p>
  
  <pre><code>public class MagicMazeGame extends MazeGame {
      public MagicMazeGame() {
          super();
      } 
      @Override
      protected Room makeRoom() {
          return new MagicRoom(); 
      }
  }
  </code></pre>