VLSI DV Interview Puzzles · All levels

create() Honors Override, new() Bypasses

With a type override installed, compare object types produced by `type_id::create` and direct `new`.

Puzzle

Difficulty: Easy · Puzzle 2 of 6 · Topic: Factory Override Puzzles

With a type override installed, compare object types produced by `type_id::create` and direct `new`.

Code

systemverilog
class base_item extends uvm_sequence_item;
  `uvm_object_utils(base_item)
  function new(string name="base_item"); super.new(name); endfunction
endclass
class fast_item extends base_item;
  `uvm_object_utils(fast_item)
  function new(string name="fast_item"); super.new(name); endfunction
endclass

initial begin
  base_item::type_id::set_type_override(fast_item::get_type());
  base_item a, b;
  a = base_item::type_id::create("a");
  b = new("b");
  $display("a=%s b=%s", a.get_type_name(), b.get_type_name());
end

Hint

Only factory-mediated creation can consult override tables.

Step-by-step solution

diagram
1) `a` is created through factory API, so type override maps it to `fast_item`.
2) `b = new(...)` directly constructs declared class and never checks factory.
3) Output is `a=fast_item b=base_item`.

Answer

Answer: `create()` returns overridden type; direct `new()` always returns declared type and ignores factory.

Why candidates get it wrong

Using `new` in reusable components silently defeats test-level overrides.

Interviewer follow-up

Where in your environment code would replacing `new` with `create` have highest leverage?

Related topics