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.
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 ?