Source – SV Verification Directory
Class
A class is a user-defined data type that serves as a blue-print for creating objects. A class includes properties(variables) and methods(functions and tasks) that manipulate data.
Example: Class
class Ex_class;
// class properties or variables
int a, b, s;
// task method
task sum (int a,b);
s = a + b;
$display("a = %0d , b = %0d, sum s = %0d", a, b ,s);
endtask
endclass
A class can be defined and used in a program, module, package, or outside of any of these. A set of classes can be grouped in a package.
// class in a package
// file pack.svh
package group_classes;
class Ex_class;
// class body as defined above
endclass
endpackage
// import a package in a program
program automatic test;
import group_classes::*;
Ex_classes cl;
// code
endprogram
Parameterized Class
Parameterized classes are similar to parameterized modules in Verilog.
Syntax
class para_class #(parameter N = 4);
logic [N-1:0] data;
function new();
data = 8;
endfunction
endclass