When/why to make function private in class?

后端 未结 7 755
攒了一身酷
攒了一身酷 2020-12-28 15:50

When should i make a function private and why is it good idea?

相关标签:
7条回答
  • 2020-12-28 16:28

    If you are designing a class - considering the way client code should use it - then you will inevitably derive an interface consisting of public and perhaps protected members.

    private members are functions and data that supports and enables those public/protected members. private functions should factor and/or modularise/structure the code needed by the non-private members, making their implementation less redundant and easier to understand.

    Summarily, you make a member private if it's not intended for direct use by client code, and only exists to support the non-private members.

    0 讨论(0)
提交回复
热议问题