VLSI DV Interview Puzzles · All levels
Template Method with Non-Virtual Wrapper
Predict output when non-virtual wrapper calls a virtual hook.
Puzzle
Difficulty: Easy · Puzzle 5 of 6 · Topic: Virtual Method Puzzles
Predict output when non-virtual wrapper calls a virtual hook.
Code
systemverilog
class base_seq;
function void run();
$display("base run pre");
body();
$display("base run post");
endfunction
virtual function void body();
$display("base body");
endfunction
endclass
class ext_seq extends base_seq;
function void body();
$display("ext body");
endfunction
endclass
initial begin
base_seq s = new ext_seq();
s.run();
endHint
Analyze dispatch at each call site separately.
Step-by-step solution
diagram
1) `run()` itself is non-virtual, so base wrapper always executes.
2) Inside wrapper, `body()` is virtual, so derived hook executes.
3) Output order: `base run pre`, `ext body`, `base run post`.Answer
Answer: Base wrapper runs, but virtual hook dispatches to derived body.
Why candidates get it wrong
People often assume non-virtual wrapper blocks all polymorphism inside it.
Interviewer follow-up
Where is this pattern used in UVM phases and callbacks?