SystemVerilog OOP Mastery · All levels

Callbacks and Policy Classes for Open Extension: Exercises

Exercises for Callbacks and Policy Classes for Open Extension.

Practice exercises

Exercise 1

Your driver must optionally insert protocol-specific idle cycles before each transfer for one test only. Callback or policy?

Solution

diagram
Use a callback around pre-drive/post-drive because the behavior is hook-oriented around driver execution, not a pure comparison algorithm.

Exercise 2

Scoreboard comparison changes between strict and mask-based rules across regressions. What pattern should own this variability?

Solution

diagram
Use policy classes (Strategy) and inject the selected policy through `uvm_config_db` so tests switch algorithm without scoreboard subclass explosion.

Related topics