Why use uvm_config_db to pass vif or configuration object is recommended?

In reply to cgales:

Hi cgales:
Here is an example,
configuration object:


class x_agent_config extends uvm_object;
  virtual x_if  x_port;
  
  uvm_active_passive_enum active = UVM_ACTIVE;
  bit coverage_enable = 1'b1;
  ...
endclass : x_agent_config

agent


class x_agent extends uvm_agent;
  x_agent_config cfg;
  ...
endclass : x_agent

perhaps an env level:


class simple_env extends uvm_env;
  simple_env_config  cfg;

  x_agent x_agt;
  y_agent y_agt;
  ...

  function void build_phase (uvm_phase phase);
    x_agt.cfg = cfg.x_agt_cfg;
    y_agt.cfg = cfg.y_agt_cfg;

    if (cfg.has_scoreboard)
    ...
  endfunction : build_phase
endclass : simple_env

Then make a base class of cases:


class simple_case_base extends uvm_test;
  simple_env env;

  simple_env_config  env_cfg;
  x_agent_config     x_agt_cfg;
  y_agent_config     y_agt_cfg;
  ...

  function void build_phase (uvm_phase phase);
    env_cfg = simple_env_config::type_id::create("env_cfg");
    config_env(env_cfg);
    
    x_agent_cfg = x_agent_config::type_id::create("x_agent_cfg");
    config_x_agent(x_agent_cfg);
    env_cfg.x_agent_cfg = x_agent_cfg;
    ...
    env.cfg = env_cfg;
  endfunction : build_phase
endclass : simple_case_base

In this situation, there is not many call. Instead, we use uvm_config_db(), we also need to call config_env() then use uvm_config_db’s set() methord. I’m confused that why don’t use direct assignment like above?

Thanks!