SystemVerilog OOP Mastery · All levels
Static and Parameterized Gotchas: Exercises
Exercises for Static and Parameterized Gotchas.
Practice exercises
Exercise 1
IDs from pkt#(int) and pkt#(byte) are interleaved, but requirement says each type starts at zero. What structural refactor solves this cleanly?
Solution
diagram
Move the static counter from shared base into the parameterized class (or per-type registry keyed by type). This scopes state to each specialization.Exercise 2
A box#(payload) clone passes unit tests, but regression shows expected data mutating after enqueue. What hidden bug pattern is likely?
Solution
diagram
clone is shallow for item handle. Deep-copy the payload object and internal dynamic arrays before enqueuing expected snapshots.