Reputation: 4402
In general, we pass a model through the controller to the view when we work with MVC. In case the model has a method that returns a certain value which will be needed several times on the same view. Which is a better practice between calling that method each time we need it's returned value or call it once and store the returned value in a variable and use that variable each time we need it? And why?
Upvotes: 1
Views: 98
Reputation: 205
In my opinion it's better to call that method once and store it into a variable. Imagine that this method contains a complex calculation, an API call or something like that. In this cases it would be much faster to calculate/execute it once and to store it in a variable.
Upvotes: 1