When/why to make function private in class?

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

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

7条回答
  •  情话喂你
    2020-12-28 16:28

    You should make a function private when you don't need other objects or classes to access the function, when you'll be invoking it from within the class.

    Stick to the principle of least privilege, only allow access to variables/functions that are absolutely necessary. Anything that doesn't fit this criteria should be private.

提交回复
热议问题