title: designing shape class with circle and triangle
body: <p>I am trying to understand the is-a vs is-like-a relationship where I read somewhere that we must try to follow design such that we always have is-a relationship and not is-like-a. Consider the classic example of shape base class and derived triangle and circle classes. So circle is-a shape and so is triangle is-a shape. The function display area was defined in the base class. Now the below program runs fine.</p>
  <pre><code>#include &quot;stdafx.h&quot;
  #include &lt;cmath&gt;
  #include &lt;iostream&gt;
  
  class shape
  {
  public:
      virtual void displayArea()=0;
  };
  
  class circle :public shape
  {
      int radius;
  public:
      circle(int radius2) :radius(radius2){  }
      void displayArea()
      {
          double area = 3.14*radius*radius;
          std::cout &lt;&lt; &quot; \n Area circle&quot; &lt;&lt; area&lt;&lt;std::endl;
      }
  };
  
  class triangle :public shape
  {
      double a,b,c;
  public:
      triangle(double a1, double b1, double c1): a(a1), b(b1),c(c1)
      {
          if (a + b &gt; c &amp;&amp; a + c &gt; b &amp;&amp; b + c &gt; a)
              std::cout &lt;&lt; &quot;The sides form a triangle&quot; &lt;&lt; std::endl;
          else
              std::cout &lt;&lt; &quot;The sides do not form a triangle. Correct me !&quot; &lt;&lt; std::endl;
          
      }
  
      void displayArea()
      {
          double s = (a + b + c) / 2;
          double area = sqrt(s*(s - a)*(s - b)*(s - c));
          std::cout &lt;&lt; &quot; \n Area triangle&quot;&lt;&lt; area&lt;&lt;std::endl;
      }
  };
  
  void main()
  {
      shape * p1[2];
      p1[0]= new circle(20);
  
      p1[1] = new triangle(5.6,8.1,10.3);
      for (int i = 0; i &lt; 2; ++i)
      {
          p1[i]-&gt;displayArea();
      }
  
      int y;
      std::cin &gt;&gt; y;
  }
  </code></pre>
  <p>Now if the requirement comes that one needs to implement <code>modifyShape</code> function where each parameter of the shape is modified based on parameter of the user then how should I change my classes such that my is-a relationship is not altered. When I look at it, I feel I will have to define a single argument <code>modifyShape</code> in circle and a 3-argument <code>modifyShape</code> in triangle. But how should this function look like in the base class?</p>
  <p>Option 1: I define both single argument and two argument <code>modifyShape</code> function in shape but that would mean i would be having an extra 2 argument function in circle and an extra 1 argument function in triangle.</p>
  <p>Option 2: I define a variable argument function <code>modifyShape</code> in shape but somehow this is not looking cleaner to me.</p>