Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Method design

 

Method design is the design of 'good' methods. From [1]:

 

The standard requires that operators = () [] and -> must be methods.
For all other functions:
IF the function is operator>> or operator<< for File I/O,
OR IF it needs type conversions on its leftmost argument,
OR IF it can be implemented using the class's public interface alone,
  Make it a non-member (and friend in the first two cases).
IF it needs to behave virtually,
  add a virtual member function to provide the virtual behaviour and implement it in terms of that.
ELSE make it a member

 

 

 

 

 

Other design guidelines:

 

 

 

 

 

References

 

  1. Herb Sutter. Exceptional C++. ISBN: 0-201-61562-2. Item 20: Class mechanics.
  2. Scott Meyers. Effective C++ (3rd edition). ISBN:0-321-33487-6. Item 3, paragraph 'Avoid duplication in const and non-const member functions'.

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml