I have to call some methods of my model several times in many controller's methods. At this moment, I am doing something like this:
$songs = (new Media)->getSongs($arguments);
I wonder is it a good idea to reuse the Media instance instead of create new in each method? (those methods work together in a single request)
I see some code base is using "Lazy Load Pattern" here:
public static function model()
{
static $instance = null;
if (null === $instance) {
$instance = new static();
}
return $instance;
}
So we can do this everywhere:
$songs = Media::model()->getSongs($arguments);
Is it a good idea to use this pattern here? Or is there any better ways to handle this case?
Thank you.