When/why to make function private in class?

Ramilol picture Ramilol · Dec 22, 2010 · Viewed 46.8k times · Source

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

Answer

Jacob Relkin picture Jacob Relkin · Dec 22, 2010

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.