Consider the following frequently occurring use patterns:
class webbroswer{public : ... void ClearCache (); void clearhistory (); void removecookies (); ...};
Then it would be natural to think of adding such a clean-up method:
class webbrowser{public : ... void cleareverything ();};
Or a way of cleaning up:
void clearbrowser (WebBrowser & WB) { wb.clearcache (); Wb.clearhistory (); Wb.clearcookie ();}
If you want to choose between a member function with the same functionality and a non-member, Non-friend function, then a high encapsulation is non-member, non-friend function. (Pay attention to the encapsulation here, let a function become a class of non-member), does not affect its become another class member function, such as the above Clearbrowser function, it can be completely as a tool class static member function) It is generally good practice to have clearbrowser placed in the same namespace as Clss WebBrowser. Like this:
namespace webbrowserstuff{ class webbrowser{... }; void clearbrowser (WebBrowser & WB); // convenience functions such as clearbrowser can declare multiple in a namespace. };
And because namespace can exist across header files, it is also convenient for such tool functions to maintain cross-header files. Summary: Remember that you should replace the member function with the Non-member non-friend function, which can increase encapsulation, wrap elasticity, and function expansion properties.
Clause 23: Ning to Non-member, Non-friend, replace the member function.