Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a number of options, if you are about design choices. </p> <p><strong>First</strong>, you can pour everything into a single class which would be terribly hard to debug and mixed several responsibilities.</p> <p><strong>Second</strong>, you can create nested classes, as you also noted, where you have better seperation of concerns / code but still have everything hardcoded and in one big source-code file.</p> <p><strong>Third</strong>, which is much more extendable, you can consider any container pattern you wish. I have listed one below which keeps your classes seperate and more easily testable should you care, as well as swappable.</p> <pre><code>interface IManagementRole { } class Dummy1: IManagementRole { public void Method1() { Console.WriteLine("Dummy1.Method1()"); } public void Method2() { Console.WriteLine("Dummy1.Method2()"); } } class Dummy2: IManagementRole { public void Method3() { Console.WriteLine("Dummy2.Method3()"); } public void Method4() { Console.WriteLine("Dummy2.Method4()"); } } static class Manager { private static Dictionary&lt;Type, IManagementRole&gt; myTypes = new Dictionary&lt;Type, IManagementRole&gt;(); static Manager() { myTypes.Add(typeof(Dummy1), new Dummy1()); myTypes.Add(typeof(Dummy2), new Dummy2()); } public static T GetManagableType&lt;T&gt;() where T: class { if (myTypes.ContainsKey(typeof(T))) { return myTypes[typeof(T)] as T; } throw new ArgumentException("Type is not a managable type.", "T"); } } class Program { public static void Main(string[] args) { Manager.GetManagableType&lt;Dummy1&gt;().Method1(); Manager.GetManagableType&lt;Dummy1&gt;().Method2(); Manager.GetManagableType&lt;Dummy2&gt;().Method3(); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload