title: Factory design pattern using enums and inheritence
body: <p>I have a conceptual problem. I'd like to use the design pattern factory, using an enum to know what type of object to create. But when it comes to inherit in another assembly, I'm stick with my enum ...</p>
  
  <p>Let me explain a case :</p>
  
  <p>I'm creating a Framework for multiple projects that manage fruits.</p>
  
  <p>I create an interface <code>IFruit</code> implemented by an abstract class <code>Fruit</code>, from which will inherit <code>Strawberry</code>, <code>Apple</code> and <code>Pear</code>.</p>
  
  <p>I create an enum <code>FruitTypes</code> which contains <code>Strawberry</code>, <code>Apple</code> and <code>Pear</code>. </p>
  
  <p>I create <code>FruitFactory</code> with a virtual method :
  <code>GiveMeANewFruit(FruitTypes newFruit)</code> which returns an <code>IFruit</code>.</p>
  
  <p>Everything's ok.</p>
  
  <p>I send my Framework all over the world and someone in our spanish plant needs to manage also bananas. </p>
  
  <p>He'll create <code>Banana</code> class that inherits <code>Fruit</code>.</p>
  
  <p>He'll create a <code>SpanishFruitFactory</code> that will inherit from <code>FruitFactory</code> and redefine virtual method <code>GiveMeANewFruit</code>, here is the code that could be in that method :</p>
  
  <pre><code>Public Override IFruit GiveMeANewFruit(FruitTypes newFruit)
  {
      if (newFruit == FruitTypes.Banana)
          return new Banana();
      else
          return base.GiveMeANewFruit(newFruit);
  }
  </code></pre>
  
  <p>But hey, here's the problem. I know languages like C# don't permit to inherit enums. So, my guy cannot add the <code>Banana</code> value to the <code>FruitTypes</code> enum.</p>
  
  <p>So, what would be the best pattern to replace the enum so I can give the outside world the capability to add new object types to my concept ?</p>
  
  <p>Knowing that I DO NOT want to have anything outside source code (no XML file, nor database nor anything else providing the types list).</p>
  
  <p>Do you have any advice ?</p>