Do_copy and do_compare

cpu_x_transaction class snippet:

1 virtual function bit compare_fields(cpu_x_transaction rhs);
2 cpu_x_transaction trans;

// Cast the object type with transaction type

3 if(!$cast(trans, rhs)) begin

Q:

  1. What is the purpose of comparing same filed in the same class by taking two handle trans and rhs ?
  2. Why $cast is required here even though both rhs and trans are same cpu_x_transaction type ?

cpu_x_transaction class snippet:

1 virtual function void do_copy (uvm_object rhs);
2 cpu_x_transaction rhs_;
3 super.do_copy(rhs);
4 $cast(rhs_,rhs);

Q:
What is the use of copying rhs_ in rhs ?
what super.do_copy do here ?

Thanks in advance …

In reply to Harshad:

The first snippet seems a bit odd. There is no need for that code from what I can see. Also, there is a compare_field with a very different prototype, but could not find a compare_fields in the UVM.

The second snippet is an an example of upcasting to get access to cpu_x_transaction properties. Please see my short SystemVerilog OOP course.