title: To abstract, or not to abstract
body: <p>thanks in advance for reading this. I don’t fully understand how/when to use abstracts so I am trying to think about it each project I work on to see if it will all click some day Smile | :)</p>
  
  <p>Also, the mix of accessibility levels (private, protected, internal) with keywords static, abstract, and override tend to leave me a little confused. How do I define this method/property/class....</p>
  
  <p>It's not all a big mystery to me but some projects have me coding in circles when dealing with these topics.</p>
  
  <p>With that said,</p>
  
  <p>I have an application that reads an XML document and outputs text and image files. I’m also storing all of the information in a database. I have it working nicely.</p>
  
  <p>The XML has a standard implementation with required fields and is used by multiple organizations to submit data to my app. All organizations should use (at least) the required nodes/elements that are outlined in the XML implementation guide.</p>
  
  <p>So, I want to have a default data object type to be able to derive a specific organization’s data type for required elements. (If this object is going to be used, these are the fields that must be implemented).</p>
  
  <p>If the org. just uses the default requirements, I can use the default object. If they use additional (optional) fields, I’ll have to create a new type inheriting the default type.</p>
  
  <p>My first thought was to use and abstract class that had protected properties for my bare minimum requirements:</p>
  
  <pre><code>public abstract partial class AbstractDataObject
  {
     protected string DataObjectName;
     protected DateTime? DataObjectDate;
     etc...
  }
  </code></pre>
  
  <p>Then, if the organization just uses the required elements of the node and no optional elements, I can use a “default” object.</p>
  
  <pre><code>internal partial class DefaultDataObject : AbstractDataObject
  {
     public new string DataObjectName { get; set; }
     public new DateTime? DataObjectDate { get; set; }
     etc...
  }
  </code></pre>
  
  <p>But, if an organization uses optional fields of the required node, I can use a derived organization data object.</p>
  
  <pre><code>internal sealed partial class OranizationDataObject : AbstractDataObject
  {
     public new string DataObjectName { get; set; }
     public new DateTime? DataObjectDate { get; set; }
     etc...
  
     //Optional fields used by this organization
     public string DataObjectCode { get; set; }
     etc...
  
  }
  </code></pre>
  
  <p>Do I need the abstract class? It seems to me I can just have a DefaultDataObject (something like):</p>
  
  <pre><code>internal partial class DefaultDataObject
  {
     public virtual string DataObjectName { get; set; }
     public virtual DateTime? DataObjectDate { get; set; }
     etc...
  }
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>internal sealed partial class OranizationDataObject : DefaultDataObject
  {
     public override string DataObjectName { get; set; }
     public override DateTime? DataObjectDate { get; set; }
     etc...
  
     //Optional fields used by this organization
     public string DataObjectCode { get; set; }
     etc...
  
  }
  </code></pre>
  
  <p>I’m just really trying to understand how to define these objects so I can reuse them per organization. Both ways seem to work, but I am hoping to understand how to define them properly.</p>
  
  <p>Getting the XML into above objects:</p>
  
  <pre><code>public DefaultDataObject ExtractXmlData(XContainer root)
      {
          var myObject = (from t in root.
          Elements("ElementA").Elements("ElementB")
                select new DefaultDataObject()
                {
          DataObjectName = (String)t.Element("ChildElement1"),
          DataObjectDate = 
                        Program.TryParseDateTime((String)
                        t.Elements("ChildElement2")
                        .ElementAtOrDefault(0)
          ),
          etc....
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>public OranizationDataObject ExtractXmlData(XContainer root)
      {
          var myObject = (from t in root.
          Elements("ElementA").Elements("ElementB")
              select new OranizationDataObject()
                {
      DataObjectName = (String)t.Element("ChildElement1"),
      DataObjectDate = Program.TryParseDateTime(
               (String)t.Elements("ChildElement2")
               .ElementAtOrDefault(0)),
      DataObjectCode = (String)t.Element("ChildElement3"),
  </code></pre>
  
  <p>etc....</p>
  
  <p>Again, thanks for reading. Don't forget to tip your wait staff....</p>
  
  <p>Joe </p>