Replacing conditional chains of type checking
<p>I stumbled across some code today that looked similar to:</p>

<pre><code>  if (myObject is MyClass1) 
     myOtherObject = new MyOtherClass1(myObject);
  else if (myObject  is MyClass2) 
     myOtherObject = new MyOtherClass2(myObject);
  else if (myObject  is MyClass3)
     myOtherObject = new MyOtherClass3(myObject);
  else if (myObject  is MyClass4)
     myOtherObject = new MyOtherClass4(myObject);
  else if (myObject  is MyClass5)
     myOtherObject = new MyOtherClass5(myObject);
  else if (myObject  is MyClass6) 
     // ...
</code></pre>

<p>I find this somewhat difficult to maintain and would like to replace it with something less cumbersome. What are my options?</p>

<p>So far I've considered a table driven approach using a dictionary but I'm not sure if that's the best option.</p>

<pre><code>// Not even sure this is valid syntax.
foreach (myClass in classes)
   if myObject is myClass
      new classes[myClass](myObject);
</code></pre>

<p>Any other ideas?</p>

<p><strong>Update</strong></p>

<p>Without going into to many details here is the basic structure of the classes:</p>

<pre><code>MyBaseClass                              MyOtherBaseClass
  |                                        |
   -MyClass1                                -MyOtherClass1
  |                                        |
   -MyClass2                                -MyOtherClass2
</code></pre>

<p>MyBaseClass and its descendants are what I would consider persistent data transfer objects. They store their data in a class specific format.</p>

<p>The closest I can come to describing MyOtherBaseClass and its descendants would be unidirectional data mappers<a href="http://martinfowler.com/eaaCatalog/dataMapper.html" rel="nofollow">[PoEAA]</a> but they mix a little business logic in as well.</p>

<p>The database only holds enough information to locate the objects and track their status. </p>
