title: Clone derived class from base class method
body: <p>I have an abstract base class <code>Base</code> which has some common properties, and many derived ones which implement different logic but rarely have additional fields.</p>
  
  <pre><code>public abstract Base
  {
      protected int field1;
      protected int field2;
      ....
  
      protected Base() { ... }
  }
  </code></pre>
  
  <p>Sometimes I need to clone the derived class. So my guess was, just make a virtual <code>Clone</code> method in my base class and only override it in derived classes that have additional fields, but of course my <code>Base</code> class wouldn't be abstract anymore (which isn't a problem since it only has a <code>protected</code> constructor).</p>
  
  <pre><code>public Base
  {
      protected int field1;
      protected int field2;
      ....
  
      protected Base() { ... }
  
      public virtual Base Clone() { return new Base(); }
  }
  
  public A : Base { }
  public B : Base { }
  </code></pre>
  
  <ol>
  <li><p>The thing is, since I can't know the type of the derived class in my Base one, wouldn't this lead to have a <code>Base</code> class instance even if I call it on the derived ones ? (<code>a.Clone();</code>) (actually after a test this is what is happening but perhaps my test wasn't well designed that's why I have a doubt about it) </p></li>
  <li><p>Is there a good way (pattern) to implement a base <code>Clone</code> method that would work as I expect it or do I have to write the same code in every derived class (I'd really like to avoid that...)</p></li>
  </ol>
  
  <p>Thanks for your help</p>