Hi,
Currently looking into the block_uart example (SystemVerilog) to check whether we should start using the truss library (Don’t have the book yet
. I am to SystemVerilog so maybe a stupid question, but why is in the example a uart_channel class defined which is almost equal to truss_channel iso instantiating an uart_channel of type truss_channel?
Kind Regards,
Roger.

#1 by mike on July 25th, 2007
Hi Roger,
Your question is not stupid at all. The truss channel is a container class object; that is; its algorithms do not depend on the datatype it manages. That’s a good candidate for templating, but as of July 2007, only one vendor has begun to support templating (there are also many issues around templating in SV, check out my posts on SV-EC on eda.org).
Now, we could have used derivation, but then would need to $cast to get back to the uart_group data type. Also derivation for container classes is an inappropriate use of OOP.
I am sure the SV vendors will eventually implement templating and the book examples will change.
So we had two choices; clone the code or use derivation. Now if SV had supported private derivation, we would have used that (this was a common technique before C++ supported templating). But SV only allows public derivation, so there is no way to ensure the safe use of the interface, nor overload the get() and put() methods (as SV does not support method overloading).
In the end, we decided that portability to different simulators was more important than using public derivation and adding a put_)/get_ () for every subclass. It’s a style decision and other coders may make a different choice.
Take care,
Mike