title: C# class design without using "Internal" or "Static"?
body: <p>I have a bunch of data I want to instantiate in a class, and for each variable I want to ensure a specific set of methods are also defined. IE:</p>
  
  <pre><code>[TypeA] VarA
  [TypeB] VarB
  [TypeC] VarC
  
  FA1() which is a function of VarA and VarB
  FA2() which is a function of VarA and VarC
  
  FB1() which is a function of VarB and VarA
  FB2() which is a function of VarB and VarC
  ...
  </code></pre>
  
  <p>As there will be a large number of variables (and hence even more functions) I want to split my source code up into manageable chunks.  So I am looking for an automatic way of ensuring that all of the functions for each variable are instantiated.</p>
  
  <p>I have come up with 3 possible methods to organize my code and I am not too happy with each of them and I am looking or advice as to which method is the better (or even if I have missed a completely different implementation method): </p>
  
  <p><strong>1. Partial Class</strong></p>
  
  <pre><code>partial class Base
  {
  }
  
  partial class Base 
  {
    [TypeA] VarA;
  
    FA1 { .. };  // function of VarA and VarB
    FA2 { .. };  // function of VarA and VarC
  }
  
  
  partial class Base 
  {
    [TypeB] VarB;
  
    FB1 { .. };  // function of VarB and VarA
    FB2 { .. };  // function of VarB and VarC
  }
  </code></pre>
  
  <p>Pros:</p>
  
  <ol>
  <li>Simple </li>
  <li>Variables can only be accessed from within class Base.  </li>
  <li>If there are two variables of the same type then the functions for each variable can implement its own function differently.</li>
  </ol>
  
  <p>Cons:</p>
  
  <ol>
  <li>Cannot automatically ensure that all functions are created for each variable</li>
  <li>Need to manually ensure that there are no name collisions between each function name.</li>
  </ol>
  
  <p>Note that the Cons may be solved by a code generator of some sort (maybe time to learn T4??) </p>
  
  <hr>
  
  <p><strong>2. Internal class</strong></p>
  
  <pre><code>class Base 
  {
    internal [ClassA] ObjA = new [ClassA]();
    internal [ClassB] ObjB = new [ClassB]();
  }
  
  class [BaseClassA]
  {
    public [TypeA] VarA;
  
    public virtual F1 { .. };
    public virtual F2 { .. };
  }
  
  class [ClassA] : [BassClassA]
  {
    public override F1 { .. };  // function of VarA and ObjB.VarB
    public override F2 { .. };  // function of VarA and ObjC.VarC
  }
  ...
  </code></pre>
  
  <p>Pros: </p>
  
  <ol>
  <li>Class hierarchy enforces that all functions are created and that variables are there to be accessed.</li>
  <li>Through use of virtual functions can create instance specific implementations of functions</li>
  </ol>
  
  <p>Cons:</p>
  
  <ol>
  <li>Use of <strong>Internal</strong> means that data is visible <strong>everywhere</strong> in the assembly.</li>
  </ol>
  
  <hr>
  
  <p><strong>3. Static data</strong></p>
  
  <pre><code>abstract class Data
  {
     static [TypeA] VarA;
     static [TypeB] VarB;
     ...
  }
  
  abstract class [BaseClassA] : Data
  {
    public virtual F1 { .. };
    public virtual F2 { .. };
  }
  
  class [ClassA] : [BassClassA]
  {
    public override F1 { .. };  // function of VarA and VarB
    public override F2 { .. };  // function of VarA and VarC
  }
  
  class Base 
  {
   [ClassA] ObjA = new [ClassA]();
   [ClassB] ObjB = new [ClassB]();
  }
  </code></pre>
  
  <p>Pros:</p>
  
  <ol>
  <li>System ensures that all routines are instantiated</li>
  <li>Data is not blasted all around the assembly</li>
  <li>Within each function you can directly reference the other variables as per the 'partial class' solution</li>
  </ol>
  
  <p>Cons:</p>
  
  <ol>
  <li>The use of <strong>static</strong> smells like I have just re-invented global data.</li>
  </ol>
  
  <hr>
  
  <p>What I want is to somehow cherry pick the best points of each method:</p>
  
  <ol>
  <li>The direct manner of accessing variables of the "Partial class"  and "Static" methods</li>
  <li>The local data of the "Partial class" method</li>
  <li>The automatic enforcing of function implementation of the "Internal" and "Static" methods.</li>
  </ol>
  
  <p>And I want to avoid:</p>
  
  <ol>
  <li>The lack of enforcing function generation in the "Partial class"</li>
  <li>The global access of data in the "Internal" method</li>
  <li>The re-invention of global data in the "Static" method</li>
  </ol>
  
  <p>If I was going to have my druthers I'd say that what I want is to somehow apply an interface  to an instance of a variable - like:</p>
  
  <pre><code>[TypeA] VarA : IFunctions;
  [TypeB] VarB : IFunctions;
  </code></pre>
  
  <p>And somehow have the compiler auto-generate the final function names from the interface names and the vaiable name.</p>
  
  <p>So can people suggest which of the 3 methods they would prefer to implement, or suggest any other methods that may suit.</p>