title: How to use abstract base class properly C#
body: <p>Hi I'm creating a geometry library in C#...</p>
  
  <p>I have an abstract class shape. 
  I have defined a class vector (also representing (x,y) points).</p>
  
  <p>I would like to use a variety of geometrical objects, curves, lines, arcs, paths etc</p>
  
  <p>To do this I've defined an abstract <code>Segment</code> class and derived a number of classes e.g. <code>LineSegment</code> (see below), <code>CurveSegment</code>, <code>ArcCircleSegment</code>, <code>BezierCurveSegment</code>, <code>HalfInfiniteLine</code> etc.</p>
  
  <p>I've also defined a class <code>Path</code> (NOT abstract) which is intended to represent a number of segments joined together (like what you might get from a drawing application). In this i include a List member of Segments (<code>List&lt;Segment&gt;</code>).</p>
  
  <p>Then i wish to derive classes from <code>Path</code>, the key example being <code>LinePath</code> which should contain only <code>LineSegments</code>. The problem i have is i'd like to be able to call the get property on a <code>LinePath</code> object assuming it'll return a <code>LineSegment</code>. Is this possible without explicitly casting each time?</p>
  
  <p>I want to avoid making <code>Path</code> abstract as i might have a path of multiple Segment types.</p>
  
  <pre><code>public class LineSegment : Segment 
  {
      private vector m_start;
      private vector m_end;
      private vector m_vector;
  
      public vector Start
      {
          get { return m_start; }
          set { m_start = value; }
      }
  
      public vector End
      {
          get { return m_end; }
          set { m_end = value; }
      }
  
      public vector Vec
      {
          get { return m_vector; }
          set { m_vector = value; }
      }
  
      public double Length()
      {
          return Vec.length();
      }
  
      public LineSegment(vector v0, vector v1):base()
      {
          this.Start.x = v0.x;
          this.Start.y = v0.y;
          this.End.x = v1.x;
          this.End.y = v1.y;
  
          this.Vec = this.End - this.Start;
      }
  }
  </code></pre>