User guide

24-50
SystemVerilog Testbench Constructs
endclass
Now, all of the methods and properties of Packet are part of
LinkedPacket - as if they were defined in LinkedPacket - and
LinkedPacket has additional properties and methods. We can also
override the parent’s methods, changing their definitions.
Abstract classes
A group of classes can be created that are all “derived” from a
common abstract base class. For example, we might start with a
common base class of type BasePacket that sets out the structure
of packets but is incomplete; it would never be instantiated. It is
“abstract.” From this base class, a number of useful subclasses can
be derived: Ethernet packets, token ring packets, GPSS packets,
satellite packets. Each of these packets might look very similar, all
needing the same set of methods, but they would vary significantly
in terms of their internal details.We start by creating the base class
that sets out the prototype for these subclasses. Since it will not be
instantiated, the base class is made abstract by declaring the class
as virtual:
virtual class BasePacket;
By themselves, abstract classes are not tremendously interesting,
but, these classes can also have virtual methods. Virtual methods
provide prototypes for subroutines, all of the information generally
found on the first line of a method declaration: the encapsulation
criteria, the type and number of arguments, and the return type if it
is needed. When a virtual method is overridden, the prototype must
be followed exactly:
virtual class BasePacket;
virtual function integer send(bit[31:0] data);