SystemVerilog OOP Mastery · All levels
Factory Pattern: Polymorphism with Type and Instance Overrides: Exercises
Exercises for Factory Pattern: Polymorphism with Type and Instance Overrides.
Practice exercises
Exercise 1
You need parity checking only in `rx_agent` traffic, not `tx_agent`. Which override should you apply?
Solution
diagram
Use `set_inst_override` on the specific `rx_agent` path so only that instance switches to the parity-aware subtype.Exercise 2
A teammate created transactions with `base_item req = new("req");` and override stopped working. How do you fix it?
Solution
diagram
Replace direct construction with `base_item::type_id::create("req")` so the factory can resolve override policy.