Choosing grandparent class

Usually when defining a new class, we will choose which class we will extends from. How about choosing the parent class of the class which we will extends from? It is possible, and I will call it a grandparent class.


How can it possible?

Recently, I go through this wonderful paper of DVCon 2016 Paper_link.

This paper talked about using Interface Classes, but when skimming through this paper, I noticed the author used a very interesting technique to decide which classes to extends from. It simply take advantages of parameterized class as below.

     class component_a (type T = uvm_component) extends T;

Have you got the idea yet? The parameter type T class will be the class the component_a extends from. Now if we has some of those classes as below:

     class component_a (type T = uvm_component) extends T;
     class component_b (type T = uvm_component) extends T;
     class component_c (type T = uvm_component) extends T;

We can use typedef to create new class type with full control of which is parent class of which.

     typedef component_a #( component_b #(component_c) ) customized_component;

This literally means that type class customized_component is component_a extends from component_b extends from component_c extends from uvm_component.


Try it on my EDAplayground

You can run an example of this method on this simple code here: -->

Now what

This is a very interesting method, but don’t be greedy since it might be painful to debug. It is now come to our abstract thinking level to take the most advantages of this.

In the Paper, the author used this method to implement all the required methods of an interface class.

In this blog Do You Want Sprinkles with That? - Mixing in Constraints, this kind of class is used to add more constraints to an existing class.



[Tags systemverilog  uvm  ]