SystemVerilog OOP Mastery · All levels

Interface Classes and `implements`

An `interface class` defines role contracts independent of inheritance tree; concrete classes adopt those roles with `implements`.

Overview

An `interface class` defines role contracts independent of inheritance tree; concrete classes adopt those roles with `implements`.

Use interface classes when multiple unrelated classes must expose the same API shape. This decouples capability contracts from base-class lineage, so you avoid forcing everything under one deep inheritance hierarchy.

In this topic

diagram
1. Concept Explained
2. Code Examples
3. SystemVerilog vs C++/Java
4. Pitfalls
5. Exercises
6. Interview Questions

Read 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.

Related topics