Create_component Versus create

What is the difference between create_component and type_id:create method of building objects ?
ALso in a legacy environment i see :

assert( $cast(msgbfm_cfg, create_object(“iosfsbm_fbrc::fbrcvc_cfg”, “msgbfm_cfg”)) )
else ovm_report_fatal(“CASTING”, “Type mismatch”);
assert( $cast(msgbfm, create_component(“iosfsbm_fbrc::iosfsbm_fbrcvc”, “msgbfm”)) )
else ovm_report_fatal(“CASTING”, “Type mismatch”);
$sformat(msg, “Creating Agent VC %s”, “msgbfm”);
ovm_report_info(“NETWORK BUILDER”, msg, iosfsbm_cm::VERBOSE_PROGRESS);

Why use create_object for one and use create_component for another ?

The type_id::create is the newer, preferred method of factory creation that has stronger type-checking at compile time, rather than at run time. The function my_class::type_id::create() will always return a type that is compatible with my_class. Whereas create_component() always returns an ovm_component that needs to be dynamically up-cast with $cast.

There reason for the create_component versus create_object has to do with the fact that factory construction requires a fixed prototype for the constructor. All classes derived from ovm_component must have two constructor arguments: a name and a parent. All other classes derived from ovm_object have only one argument in their constructor.

Hello Dave,

Is the fixed prototype requirement of the factory essentially is meant to discourage passing arguments through the constructor ?

Sometimes it is very handy to pass an integer through constructor. I am not able to achieve the same through parameters. I thunk they are fixed at compile time.

program test;

  import uvm_pkg::*;

  class compA #(int unsigned id = 10) extends uvm_component;

    
    `uvm_component_param_utils(compA#)
    //`uvm_component_param_utils(compA#(id))

    function new(string name = "compA", uvm_component parent = null);
      super.new(name, parent);
    endfunction

    function void display();
      $display("ID = %0d", id);
    endfunction

  endclass

  class env extends uvm_test;

  `uvm_component_utils(env)

    compA compa_h;

    function new(string name = "env", uvm_component parent = null);
      super.new(name, parent);
    endfunction

    function void build();
      compa_h = compA#(20)::type_id::create("compa_h", this);
      compa_h.display();
    endfunction

 endclass 

  initial begin
    run_test(); 
  end

endprogram

What is the recommended way to pass information during construction of an object ?

-Sohel

In reply to sohels:

That’s what the configuration methods do for you. Use set_config_object to pass values to your components.