Does it make sense to provide non-const reference getter

前端 未结 9 907
滥情空心
滥情空心 2020-12-16 23:58

Sometimes I need to expose some of the class members. For example in the following example class Mechanic may need direct access to Engine componen

9条回答
  •  别那么骄傲
    2020-12-17 00:18

    As I happened to get educated on recently, getters and setters smell of bad design. But, if you want it that way, providing functions to get and set m_engine (Defined by you) rather than just exposing it (You have no intervention) means that you have a plug-in point for future changes.

提交回复
热议问题