Skip to content

Private functions declared outside of the class #538

Answered by alexvanyo
PVGH19 asked this question in Q&A
Discussion options

You must be logged in to vote

The main benefit is that you can more easily identify what inputs are used in the method. If you have a method declared inside a class, those methods (for better and for worse) have access to all of the instance's parameters, properties, other methods.

A top-level method just has the parameters to the method, and that's it. If you want access to a particular parameter, or to call some instance method, you have to pass it in.

For that reason, top-level methods can lead to a data flow that's easier to understand and read. If you're looking at just newsUiState, you can know that it will only depend on those three parameters, and not on topicsRepository.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by PVGH19
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants