Hardware interview practice
How UVM Factory Type Overrides Work
A type override from base_pkt to crc_pkt is installed before any packets are created. Which creation is eligible to return a crc_pkt?
Answer choices
- A. A literal struct assignment with the same fields
- B. new base_pkt("p")
- C. A base_pkt handle allocated before the override
- D. base_pkt::type_id::create("p")
Concise answer
The answer and the key reason
Deeper explanation
Work through the implementation and tradeoffs
A type override tells the factory to substitute one registered type whenever later creation requests name another registered type. Calling `base_pkt::type_id::create` performs that lookup, discovers the replacement, and constructs the derived packet while returning it through a handle compatible with the requested base type.
A normal constructor call has no factory resolution step, so `new base_pkt("p")` creates exactly the named class. Likewise, installing an override cannot mutate or exchange instances that already exist. Overrides should therefore be configured before the relevant factory creation calls, and the replacement must be type-compatible with the original request.
What to remember
- Factory creation applies overrides
- Direct new bypasses substitution
- Existing objects never change
Practice the complete prompt
