Is there specific reason why seq_items are declared inside task body() in sequence?

Is there specific reason why seq_items are declared inside task body()? Can it be declared outside body() or it is just bad practise? All the examples I saw have them declared inside body(), so I was wondering if that is some kind of UVM coding guideline.

class example_seq extends uvm_sequence #(example_seq_item);
 
`uvm_object_utils(example_seq )
 
function new (string name = "example_seq ");
 super.new(name);
endfunction
 
task body;
 example_seq_item item;
 
 item= example_seq_item::type_id::create("item");

...
 
endtask: body
endclass: example_seq 

There is no need to declare any sequence items in your sequence. The uvm_sequence class already has the variables ‘req’ and ‘rsp’, with the appropriate type based on the sequence parameterization. These variables should be used instead of declaring new variables.

Thanks for the answer. What if I want to declare instance of another sequence type? All the examples I saw declares it inside body(). Is there specific reason?

class example_seq extends uvm_sequence;
 
`uvm_object_utils(example_seq )
 
function new (string name = "example_seq ");
 super.new(name);
endfunction
 
task body();
 another_seq  seq;

`uvm_do(seq)

endtask: body
endclass: example_seq 

It depends. If your sequence will only be dealing with one sequence_item at any one point in time, the using the req variable in the sequence base class is best. Declaring additional sequence_item variables inside a method makes it have an automatic lifetime–that might make it harder for debug tools capture that in waveforms. My suggestion is to declare sequence_item variables as class properties unless they are being used by methods that are reentrant.