title: Is "Modern C++ Design" DocumentManager design correct?
body: <p>I was going through the "Modern C++ Design" book, I saw the below code explained in "8.1 The Need for Object Factories", and I have some doubts.</p>
  
  <ol>
  <li>Is my understanding that, "CreateDocument()" should be overridden in a new derivedDocumentManager class each time a derivedDocument class is writen?</li>
  <li>If Yes, then there will be way too many derived documentManagers and needs its own Factory method!!!</li>
  <li><p>If No, then "CreateDocument()" should take an ID so that it can decide exactly what to create among a of objects. But this also means, each time a derivedDocument is created, he also should find the correct documentManager and update the CreateDocument() method. But we have to decide to have or not to have the a Factory of documentManagers as there can be few or many of them.</p>
  
  <p>My main doubt is whether this is a solution at all or if I am missing the point. According to the book, <code>CreateDocument()</code> is the GoF book's factory method. "CreateDocument()" creating a new derivedDocument based on an ID and lots of conditions at least makes sense. But lots of derivedDocumentManager does not make sense.</p></li>
  </ol>
  
  <p><code>DocumentManager</code> from the book,</p>
  
  <pre><code>class DocumentManager
  {
      ...
  public:
      Document* NewDocument();
  private:
      virtual Document* CreateDocument() = 0;
      std::list&lt;Document*&gt; listOfDocs_;
  };
  
  Document* DocumentManager::NewDocument()
  {
      Document* pDoc = CreateDocument();
      listOfDocs_.push_back(pDoc);
      ...
      return pDoc;
  }
  </code></pre>
  
  <p>Client code:</p>
  
  <pre><code>Document* GraphicDocumentManager::CreateDocument()
  {
      return new GraphicDocument;
  }
  </code></pre>