0

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)

closed as off-topic by Clive Jan 10 at 10:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow." – Clive
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please remember to ask one objectively answerable question per post - we can't have multiple questions in a single post as it doesn't suit the Q+A format, nor do questions that rely on opinion to answer rather than fact (like whether it's better for you personally to use an existing module or write one yourself). Also please ask general questions about OOP/coding style elsewhere, unless there's a Drupal-specific angle to them. Many thanks – Clive Jan 10 at 10:05
  • OK,thanks for your advice. I’ve asked the question in stackoverflow. :D – richardson Jan 10 at 11:57

Browse other questions tagged or ask your own question.