Hi ,
Is it recommended to hierarchically create objects using constructor method? If not why ?
Ex:
class a extends uvm_object;
`uvm_object_utils (a)
b my_b;
function new(string name = "a");
super.new(name)
my_b = b::type_id::create("my_b");
endfunction
enclass
In reply to dharavd:
In general you should avoid construction of other classes in the constructor of the containing class. Although you can override the factory type, you can’t override having no object constructed at all. There is no way prevent a call to super.new in a derived class.
Classes derived from uvm_component have a build_phase() method that you can use instead of the constructor new(). And there is no requirement to call super.build_phase() if you want to completely override all the build_phase() functionality in the base class.