Function call of new and create

class mem_seq_item extends uvm_sequence_item;
  //Control Information
  rand bit [3:0] addr;
  rand bit       wr_en;
  rand bit       rd_en;
   
  //Payload Information
  rand bit [7:0] wdata;
   
  //Analysis Information
       bit [7:0] rdata;
   
  //Utility and Field macros,
  `uvm_object_utils_begin(mem_seq_item)
    `uvm_field_int(addr,UVM_ALL_ON)
    `uvm_field_int(wr_en,UVM_ALL_ON)
    `uvm_field_int(rd_en,UVM_ALL_ON)
    `uvm_field_int(wdata,UVM_ALL_ON)
  `uvm_object_utils_end
   
  //Constructor
  function new(string name = "mem_seq_item");
    super.new(name);
  endfunction
   
  //constaint, to generate any one among write and read
  constraint wr_rd_c { wr_en != rd_en; };
   
endclass
 
//-------------------------------------------------------------------------
//Simple TestBench to create and randomize sequence item
//-------------------------------------------------------------------------
module seq_item_tb;
   
  //instance
  mem_seq_item seq_item;
   
  initial begin
    //create method
    seq_item = mem_seq_item::type_id::create();
     
    //randomizing the seq_item
    seq_item.randomize();
     
    //printing the seq_item
    seq_item.print();  
  end 
endmodule

Simulator Output:


Name Type Size Value

mem_seq_item mem_seq_item - @334
addr integral 4 'h4
wr_en integral 1 'h1
rd_en integral 1 'h0
wdata integral 8 'h88

question–>normally in system verilog code constructor function new() is called when u write like this
class_handle=new();
here in this case when is new function called.

initial begin
//create method (in uvm we use create method in place of (class_handle=new();))

seq_item = mem_seq_item::type_id::create();

question–>normally in system verilog code constructor function new() is called when u write like this
class_handle=new();
here in this case when is new function called. [/quote]
answer–>in uvm we use create method in place of (class_handle=new();)

In reply to Mallikarjun:

The factory create method delegates calling the constructor new() of the requested object which gives the factory an opportunity to substitute a different object from the one requested. That is the point of the factory. Directly calling the constructor removes that opportunity. See my SystemVerilog OOP course, especially the third session on the factory design pattern.

@dave_59
function new(string name = “mem_seq_item”);
super.new(name);
endfunction
instead of new constructor, why cant we use create method here…

In reply to Mallikarjun:

You MUST call the class constructor new() to bring an object into existence. And the constructor MUST call super.new(). Those are SystemVerilog requirements. Either you call it directly, or you call another method that calls it for you. Please watch the video.