I find it challenging to determine which methods should be designated as private and which should be public within a component class.
It's generally straightforward in a service to determine whether a method should be public or private, for example:
export class MyServiceClass {
private _cache = {}; // this value is private and should not be accessed externally
public accessCache(){ // this is a public API method
return this._cache;
}
public setCache(newVal){
this._cache = newVal;
}
}
Following this reasoning, all methods within a component should be private because none of them should be exposed outside of the class. (based on this post stating that a component and its view are considered one entity)
export class MyComponent {
private _getRandomNumbers(){ // this is solely used within the view
/*..*/
}
}
While this may not pose a significant issue, a video suggests that only public methods in a component should be unit tested. However, under the above logic, there seems to be no justification for having public methods in a component class. Despite this, there are still methods that are worth testing, especially those utilized within the view. This has left me perplexed about the distinction between private and public methods in the angular context.
So, the question I pose is simple:
which methods within components should be designated as public and private.