title: Adding a set accessor to a property in a class that derives from an abstract class with only a get accessor
body: <p>I have an abstract class, <strong>AbsClass</strong> that implements an interface, <strong>IClass</strong>. <strong>IClass</strong> has a couple properties with only Get accessors. <strong>AbsClass</strong> implements the properties of <strong>IClass</strong> as abstract properties to be defined in the classes that derive from <strong>AbsClass</strong>. </p>
  
  <p>So all of the classes that derive from <strong>AbsClass</strong> will also need to satisfy <strong>IClass</strong> by having the same properties with Get accessors. However, in some cases I want to be able to add set accessors to the properties from <strong>IClass</strong>. Yet if I try to override the abstract properties in <strong>AbsClass</strong> with a set accessor I get this error</p>
  
  <p><em>ConcClassA.Bottom.Set cannot override because AbsClass.Bottom does not have an overridable set accessor</em></p>
  
  <p>See <strong>ConcClassA</strong> below.</p>
  
  <p>If I have a class that is only implementing the <strong>IClass</strong> interface, but not inheriting from AbsClass then I am able to add a set accessor with out problems. See <strong>ConcClassB</strong>  below.</p>
  
  <p>I could just implement IClass at each derivation of AbsClass rather then directly for AbsClass. Yet I know from my design that every AbsClass needs to also be an IClass so I'd rather specify that higher up in the hierarchy.</p>
  
  <pre><code>public interface IClass
  {
      double Top
      {
          get;
      }
      double Bottom
      {
          get;
      }
  }
  
  abstract class AbsClass:IClass
  {
      public abstract double Top
      {
          get;
      }
  
      public abstract double Bottom
      {
          get;
      }
  }
  
  
  
  class ConcClassA : AbsClass
  {
      public override double Top
      {
          get { return 1; }
      }
  
      public override double Bottom
      {
          get { return 1; }
  
          //adding a Set accessor causes error:
          //ConcClassA.Bottom.Set cannot override because AbsClass.Bottom does not have an overridable set accessor
  
          //set { }
      }
  
  }
  
  class ConcClassB : IClass
  {
      public double Top
      {
          get { return 1; }
          //added a set accessor to an interface does not cause problem
          set { }
      }
      public double Bottom
      {
          get { return 1; }
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>So I think this will make more sense if I explain exactly what I'm trying to do rather then using the abstract example. I work for an Architecture firm and these are business objects related to an architectural design project. </p>
  
  <p>I have an abstract class <strong>RhNodeBuilding</strong> that represents one type of building on a project. There is some general functionality, like the ability to have floors, that is defined in <strong>RhNodeBuilding</strong>. <strong>RhNodeBuilding</strong> also inherits from another abstract classes that allow it be part of a larger project tree structure.</p>
  
  <p><strong>RhNodeBuilding</strong> implements from an interface <strong>IBuilding</strong> which defines a number of read only properties that all buildings should be able to provide such as <strong>TopElevation</strong>, <strong>BottomElevation</strong>, <strong>Height</strong>, <strong>NumberOfFloors</strong>, etc..etc.. Keep in mind there are other building types that do not derive from <strong>RhNodeBuilding</strong>, but still need to implement <strong>IBuilding</strong>.</p>
  
  <p>Right now I have two types that derive from <strong>RhNodeBuilding</strong>: <strong>MassBuilding</strong> and <strong>FootPrintBuilding</strong>. <strong>MassBuilding</strong> is defined by a 3D shape created by the user. That shape has a <strong>TopElevation</strong> and a <strong>BottomElevation</strong> that should be accessible through the corresponding properties, but you shouldn't be able to edit the 3D volume by changing the properties.</p>
  
  <p><strong>FootPrintBuilding</strong> on the other hand is defined by a closed curve and a height range to extrude that curve through. So not only should the class be able to return what the current elevations are but these elevations should also be able to be changed to redefine the height range.</p>
  
  <p>So in summary. All buildings (<strong>IBuildings</strong>) need to be able to return a <strong>TopElevation</strong> and <strong>BottomElevation</strong>, but not all buildings should allow <strong>TopElevation</strong> or <strong>BottomElevation</strong> to be set directly. All <strong>RhNodeBuildings</strong> are <strong>IBuildings</strong>, and classes that derive from <strong>RhNodeBuilding</strong> may or may not need to be able to directly set <strong>TopElevation</strong> and <strong>BottomElevation</strong>.</p>
  
  <pre><code>public interface IBuilding
  {
      double Top
      {
          get;
      }
      double Bottom
      {
          get;
      }
  }
  
  abstract class RhNodeBuilding:IBuilding
  {
      public abstract double Top
      {
          get;
      }
  
      public abstract double Bottom
      {
          get;
      }
  }
  
  
  
  class MassBuilding: AbsClass
  {
  
     //mass building only returns Top and Bottom properties so it works fine
      public override double Bottom
      {
          get { return 1; }
      }
  
      public override double Top
      {
          get { return 1; }
      }
  
  }
  
  
  class FootPrintBuilding: AbsClass
  {
      //Top and Bottom of FootPrintBuilding can both be retrieved and set
      public override double Top
      {
          get { return 1; }
          //adding a Set accessor causes error:
          //cannot override because RhNodeBuilding.Top does not have an overridable set accessor
  
          //set { }
      }
  
      public override double Bottom
      {
          get { return 1; }
  
          //adding a Set accessor causes error:
          //cannot override because RhNodeBuilding.Bottom does not have an overridable set accessor
  
          //set { }
      }
  
  }
  </code></pre>
  
  <p>Right now it seems like the best option is to not have <strong>RhNodeBuilding</strong> implement <strong>IBuilding</strong>, but rather have every class that derives from <strong>RhNodeBuilding</strong> implement IBuilding. That way I can define the properties from <strong>IBuilding</strong> directly rather then as overrides.</p>
  
  <pre><code>abstract class AltRhNodeBuilding
  {
      public abstract double Top
      {
          get;
      }
  }
  
  
  class AltFootPrintBuilding: IClass
  {
      public override double Top
      {
          get { return 1; }
  
         //Can't add set access to overridden abstract property
          set { }
      }
  
      //No problem adding set accessor to interface property
      public double Bottom
      {
          get { return 1; }
          set {  }
      }
  }
  </code></pre>