SystemVerilog OOP Mastery · All levels

SystemVerilog OOP Cheatsheet

Dense reference of the rules behind SystemVerilog OOP.

Objects & handles

  • class = type; object exists only after new(). A declared handle is null until then.

  • Handle assignment aliases (both point to the same object); it is not a copy.

  • Calling a method on a null handle is a fatal runtime error - guard with if (h != null).

  • Methods are automatic by default; locals are per-call, but object fields are shared.

Inheritance & polymorphism

  • Single inheritance only via extends.

  • Mark methods virtual to get dynamic dispatch through a base handle.

  • super.new() must be called (implicitly or explicitly) before using the object.

  • Forgetting virtual = static dispatch = wrong method runs (the classic bug).

Abstract / interface / parameterized

  • virtual class cannot be constructed; pure virtual methods force overrides.

  • interface class + implements emulates multiple inheritance (which SV lacks).

  • class #(type T, int N) parameterizes; each specialization has its OWN statics.

Copy, cast, and what SV lacks

  • Default copy is shallow; deep copy needs an explicit copy()/clone() that news sub-objects.

  • $cast checks runtime type for downcasts; assignment alone is not enough.

  • No operator overloading, no destructors/manual delete (GC), no friend, no exceptions.

  • Use named methods, null-out handles, packages (not namespaces), and composition.