There are lots of times where I'm not sure whether a particular method should be made private or not. For example, I'm building a class right now, which, is responsible for generating a report. This class has a buildReport method and several methods which collect the necessary data for buildReport.
// single public method
// uses a set of helper methods
public buildReport()
// helper methods
private avgSurveyTime()
private fetchVendors()
private fetchSendCounts()
private ...
I'm debating whether I should make these helper methods public. The only method I really plan on calling outside at the moment is buildReport()
. However, it might be useful to get just a list of the vendors with fetchVendors()
etc.
I see two schools of thought on this: You can always expose as little as possible. (In which case, many of my classes would only have one public method) OR you can expose all you can that might be useful to the user of the class.
Is there a good rule of thumb to use for deciding when methods should be made public/private?