SystemVerilog OOP Mastery · All levels
Pure Virtual Methods as Compile-Time Contracts
`pure virtual` methods create mandatory API contracts that every concrete subclass must implement before it can be instantiated.
Overview
`pure virtual` methods create mandatory API contracts that every concrete subclass must implement before it can be instantiated.
A pure virtual method is the strongest way to define required behavior in an abstract base class. The compiler/elaborator enforces the contract: no concrete class can exist without implementing every required method.
In this topic
diagram
1. Concept Explained
2. Code Examples
3. SystemVerilog vs C++/Java
4. Pitfalls
5. Exercises
6. Interview QuestionsRead the concept first, study the code examples, compare against C++/Java, then test yourself with the exercises and interview questions.
Virtual dispatch table resolution
diagram
VIRTUAL DISPATCH TABLE (VTABLE STYLE)
handle type: component object type: axi_driver
+----------------------+ +------------------------+
| component handle c |--->| vptr ----------------+----+
+----------------------+ +------------------------+ |
v
+----------------------------+
| axi_driver vtable |
| [0] build_phase() |
| [1] run_phase() override |
| [2] report_phase() |
+----------------------------+
c.run_phase() resolves through vptr at runtime, not handle static type.