Use separate class definition sections

Frequently you have functions that must be public, but that are not meant to be called by clients. Consider a function that is called only by another related class which you don't want to make a friend. To clarify the use of these members, separate them in the class declaration into sections according to who usually calls them, with a comment at the front of each section. Place private virtual member functions that are meant to be overridden ahead of public functions that clients and subclasses should not call.

      
      class TFoo {
      public:
      
          // Normal client functions:
          void Member1();
          ...
      
          // Seldom-used functions:
          void BlueMoon1();
      
      protected:
          ...
      
      
    
      public:
          // Internal use only; do not call:
          void MagicMember1();
      
      private:
          ...
      };
Public and internal aren't the only categories into which members fall: feel free to divide them up into as many sections as you like to help people to understand them, for example, API, SPI, and internal.

NOTE If the set of users of internal public members is small, fixed, and known, use the C++ friend feature and make them private instead. This gives you more control (see "Friend functions and classes" on page 102).


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker