What is the best way to design this class hierarchy?
<p>I have a database table which contains an <code>ID</code> column and a <code>Name</code> column. I am tasked with designing a program that accepts one of the IDs as an argument to <code>Main()</code>.</p>

<p><strong>Bold is edit 2</strong></p>

<p><strong>I need to use that ID which must exist in the database, to correspond to some code to run</strong>. Each row in the table corresponds to slightly different code, but a lot of them share a lot of code. I need a design that will minimize code duplication.</p>

<p>So far what I've developed is an abstract base class that has an abstract <code>Int32</code> field <code>ID</code> to enforce derived classes having their corresponding ID in the database. That way I can reflect over the derived classes to find the one whose ID matches the <code>Main()</code> argument and instantiate that class. Then I just call the virtual methods from <code>Main()</code> which runs the most derived code that has been defined.</p>

<pre><code>public abstract class Base {
    public abstract Int32 Id { get; }    
    public void Foo() {
        // Do something
    }
}

public class Derived {
    public override Int32 Id { get { return 42; } } 
    public void Foo() {
        // Do something more specific
    }
}
</code></pre>

<p>Does anyone have any better ideas how to achieve what I want? I like the idea of keeping the ID right in the class definition, but I'm open to changing that if it makes sense.</p>

<p>Thanks!</p>

<p><strong>EDIT:</strong></p>

<p>One thing I don't like about this is that I have to reflect over each derived type and instantiate that type to check the ID. Does anyone have a better idea on how to do that?</p>
