Part 2 · OOP for Verification · Intermediate

Static, Encapsulation & Parameterized Classes

Hub — static members, access control, parameterized classes, class constants and enums, and extern method organization.

Overview

Basic classes get you objects with properties and methods. Production verification code needs more: class-level state shared across every object (static members), access control so users of your class cannot reach into its internals (local / protected), and parameterization so one class definition serves many data widths and transaction types. These features are what separate a throwaway testbench class from a reusable VIP base class.

Each feature changes the semantics of the class, not just its syntax. A static property has a different lifetime than an instance property. A parameterized class specialization is a distinct type with its own static members. Getting these semantics wrong produces bugs that compile cleanly and fail at runtime — a favorite source of interview questions.

Sub-topics

  1. Static Properties & Methods — class-level state, ID counters, static method restrictions.

  2. local, protected & Encapsulation — access control semantics and VIP base-class design.

  3. Parameterized Classes — value/type parameters, specializations as distinct types.

  4. Constants & Enums in Classes — const properties, enum-typed fields, lookup tables.

  5. extern Methods & Class File Organization — prototypes, :: scope, include-based libraries.

diagram
CLASS FEATURES TOPIC MAP

  class my_txn;
    │
    ├─ static int count;              ◄── STATIC: one copy per CLASS
    │                                      (not per object)
    ├─ local rand bit [7:0] key;      ◄── ENCAPSULATION: hidden from
    ├─ protected int retries;              outside / visible to children
    │
    ├─ const int MAX_LEN = 16;        ◄── CONSTANTS & ENUMS:
    ├─ kind_e kind;                       read-only + named values
    │
    └─ extern function void print();  ◄── EXTERN: prototype here,
                                          body elsewhere via my_txn::print

  class fifo #(type T = int, int DEPTH = 8);   ◄── PARAMETERIZED:
    // fifo#(byte,16) and fifo#(int,8)             one template,
    // are DIFFERENT types                          many types

Key takeaways

  • Static members belong to the class — one copy shared by all objects.

  • local/protected hide internals so base classes stay safe to extend.

  • Each parameterized-class specialization is a distinct type with its own statics.