SystemVerilog OOP Mastery · All levels

No Multiple Inheritance: Interface Classes + Composition: Exercises

Exercises for No Multiple Inheritance: Interface Classes + Composition.

Practice exercises

Exercise 1

You have class `driver_base` and want reusable CRC behavior from `crc_engine`. Implement this without multiple inheritance.

Solution

diagram
Keep `class my_driver extends driver_base`, add a `crc_engine crc;` member, construct it in `new`, and delegate CRC-related calls through wrapper methods.

Exercise 2

Design a class that must be both `resettable_if` and `traceable_if` while still extending `uvm_component`.

Solution

diagram
Define `class my_comp extends uvm_component implements resettable_if, traceable_if;` and provide all required interface-class methods. Put shared tracing implementation in a composed helper object.

Related topics