jao16 Posted October 27, 2011 Report Share Posted October 27, 2011 Hello Hello all I am defining a test library as such: package my_test_lib_pkg; class my_test_base extends uvm_test; `uvm_component_utils(my_test_base) // declare an instance of the configuration, environment and agent classes my_cfg cfg_0; my_env env_0; my_agent agent_0; // constructor function new(string name = "my_test_base", uvm_component parent_null); super.ew(name, parent); endfunction : new // Now defining the build() phase. // In the build() phase, i would generate the above classes as such: function void build(); cfg_0 = my_cfg::type_id::create("cfg_0", this); env_0 = my_env::type_id::create("env_0", this); agent_0 = my_agent::type_id::create("agent_0", this); endfunction : build However, in some case i have seen the following code to generate the required instances: cfg_0 = new(); env_0 = new(); agent_0 = new(); So my question is a) what is the difference between create() and new() ? when should one use create() instead of new() and vice versa Thanks in advance JO Quote Link to comment Share on other sites More sharing options...
bhunter1972 Posted October 27, 2011 Report Share Posted October 27, 2011 Use create() if you will ever want to use the factory to override the base class. If you new() your classes, you won't have the option of later using the factory without changing the code. We use create() for everything*, because you never know when you'll want to override the base class to do something else. It adds a little bit of overhead, but it's usually worth it. *I don't use create for TLM instances. Doesn't seem likely that I'll ever override those. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.