I have a general “best practices” question.
I’m setting up a Yii application that will make heavy use of three objects. I’ve set up a “beforeAction” a parent controller, that all others inherit from. That beforeAction sets the three objects (let’s call them A, B and C) up as components, so they will be available throughout the applications via Yii::$app->A, Yii::$app->B, and Yii::$app->C. So far so good. It turns out the the methods in object C make very heavy use of objects A and B - referring to them constantly.
So… my question is: within Object C, is it better to just assume that Yii::$app->A and Yii::$app->B exist, and refer to them directly, over and over again? I’m tempted to create private variables in C that hold A and B, so I can refer to them more easily and so I can test once for the existence of A and B right when C is created. But will that create a copy of A and B?
Is there a best practice or design pattern for this sort of set up?
Thanks for your help.