title: Herb Sutter's article on making virtual functions private
body: <p>I read Herb Sutter's article <a href="http://www.gotw.ca/publications/mill18.htm" rel="nofollow noreferrer">http://www.gotw.ca/publications/mill18.htm</a> on virtual functions and how they should be declared private by default. Making a virtual function public would make it serve as an interface and customizer, and the suggestion is to separate the interfacing from the customization behavior, as the article suggests. </p>
  
  <pre><code>class shape
  {
    protected:
      void set_area(double area)
      {
        area = area;
      };
    private:
      double area;
      virtual void compute_area() = 0;
  };
  class square
  {
  
    private:
      double length;
      void compute_area()
      {
        set_area(length*length);
      }
  };
  
  </code></pre>
  
  <p>If we consider these classes, we see that we can never call the area function from outside of either class because they are made to be virtual since we don't want the virtual function to serve as the interface between the class and the "outside world" as Sutter suggested. If I understand him correctly, to use the template method, and if I want to compute the area on a <code>shape</code> object, I'd need to provide a public non-virtual function to <code>shape</code> class. So something like this?</p>
  
  <pre><code>class shape
  {
    public:
      void interfacer()
      {
        compute_area();
      }
    protected:
      void set_area(double area)
      {
        area = area;
      };
    private:
      double area;
      virtual void compute_area() = 0;
  }
  </code></pre>
  
  <p>Doesn't that seem redundant over being able to just simply do:</p>
  
  <pre><code>shape *ptr = new square();
  ptr-&gt;compute_area(); 
  </code></pre>
  
  <p>if we were to make the virtual function public? </p>
  
  <p>I reread the article and he said the public virtuals should be "Rarely if ever" used. I wonder if he would think the above is one of those instances where it'd be appropriate to make the virtual function public instead of private. </p>