In UVM (Universal Verification Methodology), object creation is a very common operation. While writing testbenches, there are two ways of creating objects:
- Using the constructor
new() - Using the factory method
create()
Although both are used to create objects, they serve very different purposes in UVM. Understanding this difference is critical for writing reusable, scalable, and factory-override friendly testbenches.
new() in UVM
new() is the standard SystemVerilog constructor used to directly create an object of a specific class.
Key Points
- Creates an object directly
- Bypasses the UVM factory
- Object type is fixed at compile time
- Factory overrides will NOT work
Example:
my_driver drv;
drv = new("drv");
create() in UVM
create() is a UVM factory-based method used to create objects via the UVM factory.
Key Points
- Object is created through the factory
- Supports type and instance overrides
- Enables reusability and configurability
- Recommended for all UVM components and sequence items
Example:
my_driver drv;
drv = my_driver::type_id::create("drv", this);
Why UVM Prefers create()
- One of UVM’s biggest strengths is factory override.
- Using
create()allows you to replace a component without changing existing code.
Tip: Always use create() for UVM components and sequence items.
Use new() only for simple, non-factory objects.