title: Generic factory
body: <p>suppose I have a TModel:</p>
  
  <pre><code>TModelClass = class of TModel;
  TModel = class
    procedure DoSomeStuff;
  end;
  </code></pre>
  
  <p>and 2 descendants:</p>
  
  <pre><code>TModel_A = class(TModel);
  TModel_B = class(TModel);
  </code></pre>
  
  <p>and a factory :</p>
  
  <pre><code>TModelFactory = class
    class function CreateModel_A: TModel_A;
    class function CreateModel_B: TModel_B;
  end;
  </code></pre>
  
  <p>Now I want to refactor a bit :</p>
  
  <pre><code>TModelFactory = class
    class function CreateGenericModel(Model: TModelClass) : TModel
  end;
  
  class function TModelFactory.CreateGenericModel(Model: TModelClass) : TModel
  begin
    ...
    case Model of
      TModel_A: Result := TModel_A.Create;
      TModel_B: Result := TModel_B.Create;
    end;
    ...
  end;
  </code></pre>
  
  <p>So far it's ok, but every time I create a <code>TModel</code> descendant, I have to modify the factory <code>case</code> statement.</p>
  
  <p>My question: Is this possible to create a 100% generic factory for all my <code>TModel</code> descendants, so every time I create a <code>TModel</code> descendants I don't have to modify <code>TModelFactory</code> ?</p>
  
  <p>I tried to play with Delphi  2009 generics but didn't find valuable information, all are related to basic usage of <code>TList&lt;T&gt;</code>and so on.</p>
  
  <p><strong>Update</strong>
  Sorry, but maybe I'm not clear or don't understand your answer (I'm still a noob), but what i'm trying to achieve is :</p>
  
  <pre><code>var
    M: TModel_A;
  begin
    M: TModelFactory.CreateGenericModel(MY_CONCRETE_CLASS);
  </code></pre>