Member functions for derived information in a class

后端 未结 6 1558
你的背包
你的背包 2021-01-22 13:39

While designing an interface for a class I normally get caught in two minds whether should I provide member functions which can be calculated / derived by using combinations of

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-22 14:21

    The STL has basically aimed for small interfaces, so in your case, if and only if getSelectedDocs can be implemented more efficiently than a combination of isDocSelected and getDoc it would be implemented as a member function.

    This technique may not be applicable anywhere but it's a good rule of thumbs to prevent clutter in interfaces.

提交回复
热议问题