Effective C++ 23. Prefer non-member non-friend functions to member functions

来源:互联网 发布:中国网络焦点台赵伟 编辑:程序博客网 时间:2024/04/29 20:25
class WebBrowser {public:    ...    void clearCache();    void clearHistory();    void removeCookies();    ...};
class WebBrowser {public:    ...    void clearEverything();    ...};

greater encapsulation is the non-member non-friend function

void clearBrowser(WebBrowser& wb) {    wb.clearCache();    wb.clearHistory();    wb.removeCookies();}
// header "webbrowser.h"namespace WebBorwserStuff {    class WebBrowser {...};    ...}// header "webbrowserbookmarks.h"namespace WebBorwserStuff {    ...}// header "webbrowsercookies.h"namespace WebBorwserStuff {    ...}
阅读全文
0 0
原创粉丝点击