Is it fair to say that it is good practice to default everything to private up when defining a class?
For example, for my public interface I would set my class something like this:
class foo {
private var x
private var y
//even get and set are private,
//public only if necessary
private get/set method for variables
//main function
private coreFunc () {...}
//helper function
public callCoreFunc() {
coreFunc()
}
}
I'm used (and got used from my algorithm teacher) that everything in a class should be private, except for the methods that the user need to call (with wrapped helper function.)
Is this a good way to see "public interface" or is this too strict?
coreFunc
topublic
and let the compiler (by throwing an error for attempts to access a private member) and documentation (by not mentioning the private members as part of the API) do the rest. – Bart van Ingen Schenau Sep 14 '18 at 9:28