Importance of the clone( ) method

In reply to NiLu:

The OVM and UVM mechanisms are the same. The OVM added the virtual do_copy() methods as a hook to the non-virtual copy() methods. This might be to get their field automation macros to work.

In reply to swethasundararaj:

class base;
int p1;
  function void copy(base orig);
    this.p1 = orig.p1;
  endfunction
  virtual function base clone(base orig);
    base h;
    h  = new;
    h.copy(orig);
    return h;
  endfunction
endclass
class ex_base;
  int p2;
  function void copy(base orig);
    super.copy(b);
    this.p2 = orig.p2;
  endfunction
   virtual function base clone(base orig);
    ex_base h, h_orig
    h  = new;
    $cast(h_orig, orig)
    h.copy(h_orig);
    return h;
  endfunction
endclass
 
base b1,b2;
ex_base eb1, eb2;
initial begin
   eb1 = new; eb2 = new();
   eb2.p2 = 5;
   b1 = eb1; b2 = eb2;
   b1.copy(b2); // p2 is not copied
   eb1.copy(eb2); // p2 is copied
end