需要PHP OOP编码建议

OOP always has lots of classes and their methods. If we need to use several subclass methods or properties that belong to the same class, should we get the high level class first or it's better to use them seperately? This is an example to show my concern:

Approach I: define variables from the top class seperately

$var1 = \Drupal::routeMatch()->getRouteName();
......(some process that relies on $var1)

$var2 = \Drupal::routeMatch()->getRawParameters('taxonomy_term');
......(some process that relies on $var2)

Approach II: get the common class first

$route = \Drupal::routeMatch();
$var1 = $route->getRouteName();
......(some process that relies on $var1)

$var2 = $route->getRawParameters('taxonomy_term');
......(some process that relies on $var2)

You can assign expressions inline. () causes the return to do 'this first', then return outside of the brackets.

$var1 = ($route = \Drupal::routeMatch())->getRouteName();
$var2 = $route->getRawParameters('taxonomy_term');

You can see this as a working demo using some example classes that mimic your environment.