Difference between function new () and function build()

Whats is the main difference between function new() and function build?

Also can I create instance of sequence item in my uvm_sequence inside function new()? or it has to be in function build()

I am creating instance in this fashion

cfg = WigigCltCfgSequenceItem::type_id::create(“cfg”);

I assume you mean the build_phase() method of classes derived from uvm_component. We recommend putting everything in the build_phase instead of new() because SystemVerilog does not allow you to completely override new(). Whenever you override a class, your overridden constructor has to call super.new() as the first statement (if you don’t, systemverilog will implicitly insert the call for you). By putting construction-like functionality into the build_phase(), when you override the class, you are not required to call super.build_phase(). This gives you a lot more flexibility as you override classes.

uvm_sequences has a body() method, not a build(). we recommend constructing sequence items in the body() method, not new() because you only need to construct an item once the sequence has started. But the UVM does not care when you do it.

In reply to dave_59:

Correct me if I am wrong here,
We just need to define the new() function in our source code.
As recommended we should use create() method to create the objects. Anyway this create method calls the new() method for us automatically.

Thank you

In reply to Ujjwal Kaushik:

In reply to dave_59:
Correct me if I am wrong here, We just need to define the new() function in our source code.
what is meant by source code here. Are you talking of DUT?
Thank you

In reply to Ayush:

The UVM has a phased approach withe the build_phase, connect_phase etc. Each phase is assigned a certain functionality.
There is only a build-function in the RAL nowhere else. And this is not used to construct the Registers.
new() is the constructor of a class.