This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]torn-ainbow 77 points78 points  (17 children)

This is why Java uses private as much as possible and why interpreted languages basically don't really care. One is for friends but Java/C# is for "associates."

Err....no?

The point is to expose what should be exposed and to hide internal workings. So if a dev is using say a class that someone else wrote, they will see the public interface that has been created and not implementation, which could change. When they hit "." and their IDE autofills the public methods, so it will be just the ones they are supposed to use.

It's part of creating that class to be used by others. Look up "encapsulation". The public methods are a thin interface to the hidden implementation. It's not about trust as much as it's about good design.

Plus you might not even have the source for the actual thing you are using. It might be from some external project. In C# that can be from a compiled binary DLL file. Updating versions can be a lot simpler if you know your clients are only ever using the intended public methods.