SystemVerilog OOP Mastery · All levels

Classes and Objects: Concept Explained

Concept Explained for Classes and Objects.

Concept

In short: A class declares a type and behavior, but no storage exists until you call new(). This separation is central in verification because transaction objects are created dynamically and passed through drivers, monitors, and scoreboards by handle.

A class is a blueprint; the simulator allocates an actual object only when new() executes. Declaring packet p; creates a handle variable that can point to an object, and its initial value is null. In practice this means object lifetime is explicit and tied to construction points in your testbench flow.

When you write packet p = new(); p.randomize(); you first allocate heap storage for packet fields, then operate on that object. The pattern is common in sequence item generation because randomization must happen on a concrete object, not on an unconstructed handle.

The key design consequence is that object creation timing matters for debug and reproducibility. If construction is hidden in many helper layers, null-handle errors and stale configuration become hard to trace. Teams usually keep construction near ownership boundaries: creator components allocate, consumers only use.

Related topics