title: Object Oriented Design / Design Pattern scenario
body: <p>I have 3 different type of shape diagrams say <code>Rectangle</code>, <code>Cube</code>, <code>Circle</code>, I want to define classes for them such that</p>
  
  <ul>
  <li><p>All classes would have Title &amp; Color property/method, </p></li>
  <li><p>Circle &amp; Rectangle would have additional method Area, </p></li>
  <li><p>Similarly Cube would have Volume method rather than Area method. </p></li>
  </ul>
  
  <p>There is a method in which I get the reference of of 'object', following is sample method</p>
  
  <pre><code>public void ShapeClicked(object obj)
  {
  // Check the type of obj &amp; type cast it accordingly &amp; call the method on that object
      object obj = new Circle();
  
      if (obj is Circle)
      {
          Circle circleObj  = (Circle)obj;
          circleObj.GetArea();
      }
      else if (obj is Rectangle)
      {
          Rectangle rectangleObj = (Rectangle)obj;
          rectangleObj.GetArea();
      }
      else if (obj is Cube)
      {
          Cube cubeObj = (Cube)obj;
          cubeObj.GetVolume();
      }
  }
  </code></pre>
  
  <p>How can I design my classes such that in 'ShapeClicked(object obj)' method </p>
  
  <ul>
  <li><p><strong>a)</strong> I need not to check the type every time (should happen at run time), (This is important for me because I have many methods like 'ShapeClicked' which requires me checking the type)</p></li>
  <li><p><strong>b)</strong> if object is of Circle then it would get only Area method, similarly for Cube object it would get only Volume method.</p></li>
  </ul>
  
  <p>I can think of two approaches</p>
  
  <ul>
  <li><p>Put all the methods &amp; properties in base class &amp; only override required methods in derive class. Create a Factory method/class which would return the reference of Base class. With this approach my 'b' requirement does not meet</p></li>
  <li><p>Put only common methods/property (like color) in base class &amp; add additional methods in derive class. This does not solve #a :(</p></li>
  </ul>
  
  <p>Can anybody suggest me some solution which solves both #a &amp; #b</p>