Member functions for derived information in a class

后端 未结 6 1638
你的背包
你的背包 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:04

    I think its fine to have getSelectedDocs as a member function. It's a perfectly reasonable operation for a DocContainer, so makes sense as a member. Member functions should be there to make the class useful. They don't need to satisfy some sort of minimality requirement.

    One disadvantage to moving it outside the class is that people will have to look in two places when the try to figure out how to use a DocContainer: they need to look in the class and also in the utility namespace.

提交回复
热议问题