I have a class say photo and code like
class photo
{
public function __construct($UserWhosePhotoToBeGetObj)
{
$this->UserWhosePhotoToBeGetObj = $UserWhosePhotoToBeGetObj
}
}
public function getPhoto()
{
// some complex logic and query to get detail of photo of user.
}
Now the problem is when i want to get photo of multiple users and if i called this class in loop, then many query will be fired and if I create class photoArr then I need to write complex logic in both classes.
“photo” sounds like a data class. Data classes should not contain logic for fetching things. Passing in an “user for which to get photo” in the constructor seems rather wrong as well.
Such logic should probably go in a PhotoFetcher class that has the logic your current getPhoto has. For instance getPhotoForUser( User $userForWhichToGetPhoto ). It could also support batch fetching.