I’m coming up against a few unknowns in my attempt to best design my OVM verification environment. Maybe some of you with more experience in OOP can help me think through this.
My two main questions are:
-
Is there a way to determine the class of an object? Is the only way to cast it and then check to see if the $cast succeeded or failed, or is there another way?
-
If I’m trying to determine if an object is of a particular subclass, is it better to provide some class method that would return an identifier that corresponds to the object’s class? or is it just as well to try and $cast the object into a particular subclass and see if it succeeds. In terms of simulator processing time, is it terribly expensive to do many $cast operations in an effort to determine the class type of a large number of objects? If $cast’ing lots of objects adds 12 hours to my simulation, I may try to do things differently.
Those are my basic questions, now here’s the background.
I have a pure virtual base class for a particular transaction. That base class will be extended into lots of subclasses. The subclasses have lots of common functionality, which I’ve defined as virtual functions in the base class. Each of the subclass transactions also has a few unique properties or methods which the other subclasses do not have. These are not in the virtual base class.
Once the transactions are created, there are OVM drivers, monitors, scoreboards, etc in my environment that receive these transactions. Some of them will interact with the transactions only via the common base class interface. Some, though, will need to know what kind of transaction this is, and then use the transaction’s unique methods or properties.
So what is the best way to structure such a system? The two options I see are: 1) to include all the methods of all the transactions in the virtual base class. This seems like too much extra work and not very efficient as many of the transactions will have to define lots of methods that don’t do anything because they don’t have that particular unique data or action. The other option is 2) in each of the OVM components that need to operate on an object’s unique methods or properties, that component tries $cast’ing the object to the subclass that it expects the object to be. If the $cast succeeds, the component can then operate on it. If the $cast fails, then the component assumes it isn’t intended to handle that object and moves on to the next one.
In short, if you have lots of different kinds of objects that have basically the same properties and methods, but each have some unique set of properties and methods from all the others, how best do you structure that using OOP inheritance?
If anyone has opinions or thoughts, I’m interested.
-gb