SV Interface classes in UVM based environment

In reply to dave_59:

Casting is bad style.

The function didn’t specifically state that it expects something that extends uvm_object as an input. Code where I pass in an implementation of the interface that does not extend uvm_object will compile, but will fail at run time.

Also, if you cast, you get two variables that refer to the same object:


function do_stuff(some_interface_class arg);
  uvm_object arg_as_uvm_object;
  if (!$cast(arg_as_uvm_object, arg))
    $fatal(0, "Cast error");

  // use 'arg_as_uvm_object' because we want to use functions defined in
  // 'uvm_object'
  arg_as_uvm_object.print();
 
  // ... use 'arg' further, because we need to use the functions defined 
  // the interface
  arg.some_cool_function();
endfunction

But it works is not the only criterion by which code should be developed.